Copy Code code as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<script src= "Js/jquery-1.3.2.js" ></script>
<script type= "Text/javascript" ><!--
$ (function () {
$ ("#aAttr1"). Click (function () {
$ (": Text"). attr ("Value", $ ("#divTest"). attr ("id");
})
$ ("#aAttr2"). Click (function () {
$ (": Text"). attr ("Value", function () {
Return $ ("#divTest"). attr ("id");
});
})
$ ("#aAttr3"). Click (function () {
$ (": Text"). attr ({value: "Test2"});
})
$ ("#aAttr4"). Click (function () {
$ ("#inputTest2"). Removeattr ("value");
})
})
--></script>
<title> Untitled Document </title>
<body>
<form>
<input id= "InputTest1" type= "text"/>
<input id= "InputTest2" type= "text" value= "test"/>
<div id= "Divtest" >123</div>
<a href= "#" id= "AATTR1" > Displays the id method of the div in the text form 1</a>|
<a href= "#" id= "AATTR2" > Displays the id method of the div in the text form 2</a>|
<a href= "#" id= "AATTR3" > Display in text Form test2</a>|
<a href= "#" id= "AATTR4" > Remove InputTest2 's value attribute </a>|
<input type= "Reset"/>
</form>
</body>
1.ELEMENT.ATTR (name)
Description: Used to get the Name property value of an element, as in the example $ ("#divTest"). attr ("id") gets the ID value of the divtest.
2.element.attr (Name,value)
Description: Used to set the Name property value for an element, such as $ (": Text") in the example. attr ("Value", $ ("#divTest"). attr ("id") assigns the Divtest ID value to the value of the text form.
Note: The example (": Text") is used to get the element with the input form type text, and other forms can be obtained by the same method, such as <input type= "button"/> is available in $ (": Button"). The return value is array (element), and you can also use $ (": input") to get all the input elements ... To get and set the text and value values of an element in jquery, you can also use Element.text ()/element.text (value), Element.val ()/element.val (value), Use the same as element.html (), if you have questions can be thread, I will explain
3.element.attr (name,function)
Description: The Name property value used to set an element is similar to the previous one, except that the value here can be written as a function and more flexible.
4.element.remove (name);
Description: The Name property used to delete an element.