jquery obtains the current value value by Name,id name

Source: Internet
Author: User

jquery Gets the current value value by Name,id name is the attribute value of the input tag, and jquery provides the attr () method for setting/Change attribute values$("Input:text"). attr ("name"));$("Input:text"). Prop ("name");//You can also get properties using the Prop () method$("*[name= ' name ']"). Val ();//Get Vlaue value$ ("*[name= ' name ']"). attr (' id ', ' name ');//Add ID name$ ("*[name= ' name ']"). After (' <div>hello world</div> ');//add an element outside the currentjquery uses the Name property to value the method alert ($ ("Input[name= ' inputtest ')"). Val ()); Alert ($ ("Input[type= ' text ']"). attr ("id"));//This is the value of the ID, easy to remember to write here$("Input[name= ' inputtest ')"). each (function() {alert ($ ( This). Val ());}) Alert ($ ("Input[name= ' inputtest ']") [0].value); alert ($ ("Input[name= ' inputtest ']") [1].value); alert ($ ("Input[name= ' inputtest ']"). Get (0). value);//You can also get a value here, equal to the two lines aboveAlert ($ ("Input[name= ' inputtest ']"). Get (1). Value); Value by name: $ ("Input[name= ' mobile ']"). Val () is based on the ID value: $ ("#mobile_reg_form"). HTML () takes the value of traversal by name: $ ("Input[name= ' mobile ']"). each (function() {alert ($ ( This). Val ()); }) remove input from the form:<script type= "Text/javascript" language= "JavaScript" charset= "UTF-8" >$ (document). Ready (function(){    vara=$ ("Form input"); $.each (A,function(name,object) {alert (name+":"+$ (object). val ());    }    );    }); </script>Get the value (multiple cases): $ ("Input[name= ' mobile ']") [0].value $ ("Input[name= ' mobile ']"). Get (1). ValueAdd a Delete style-----jquery--------add a style to a label: $ ("#id"). AddClass ("style")); Delete a label's style: $ ("#id"). Removeclass ("style")); Note:The "#id" ID is the name of the corresponding CSS style that corresponds to the id,style of the label

jquery obtains the current value value by Name,id name

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.