JQuery Learning Notes Element attribute control _jquery

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.