jquery Gets the value sample code inside the form element

Source: Internet
Author: User
This article for you to get a detailed introduction through jquery to obtain table cell element checkbox, radio, and other values, there is a need for friends can refer to the hope for everyone to help

jquery notes:

Copy Code code as follows:


$ ("Input[name= ' Radio_name ']:checked"). Val ()


<input type= "Radio" value= "1" name= "Radio_name"/>1


<input type= "Radio" value= "2" name= "Radio_name"/>2


<input type= "Radio" value= "3" name= "Radio_name"/>3




Online is too messy, and different versions of jquery may be written differently, after searching and experimenting, the following is the
of jquery version 1.3.2.

jquery Radio value, checkbox value, select Value, Radio selected, CheckBox selected, select selected, and related settings:


gets the value of a set of radio selected items: var item = $ (' input[name=items][checked] '). Val ();





gets the text of the Select selected item


var item = $ ("select[@name =items] option[@selected]"). Text ();


gets the text of the Select selected item: var item = $ ("Select[name=items] option[selected]"). Text (); or


$ ("Select[name=items]"). Find ("option:selected"). Text ();


The second element of the Select Drop-down box is the currently selected value: $ (' #select_id ') [0].selectedindex = 1;


Select dropdown box The element of value = ' Val ' is currently selected: $ ("Select[name=items] option[value= ' val '"). attr ("Selected", "Selected");


Radio The second element of the radio group is the current selected item: $ (' input[@name =items] '). Get (1). checked = true; or $ (' input[name=items] '). attr ("Checked", 1′);

The element of value = ' val ' of
Radio is currently selected: $ (' input[name=items][value= ' Val ']). attr ("Checked", "checked");


Get Value:


text box, text area: $ ("#txt"). attr ("value");


Multiple-selection box checkbox:$ ("Input[name= ' checkbox ': Checked]"). each (function () {


var val = $ (this). Val ();


});


Single Group Radio: $ ("input[type=radio][checked]"). Val ();


drop-down Box Select value: $ (' select '). val ();


dropdown Box Select the selected text value: $ ("select"). Find ("option:selected"). Text ();





Control form elements:


text box, text area: $ ("#txt"). attr ("value", "); Empty content


$ ("#txt"). attr ("value", ' 11′ '); Fill Content


Multi-selection box checkbox:

The second element of the
checkbox is ticked: $ ("Input[name=items]"). Get (1). checked = true; Tick


$ ("Input[name=items]"). Get (1). checked = false; No tick


checkbox's value= ' Val ' front tick: $ ("input[name=item] [value= ' Val ']"). attr ("Checked", true); or $ ("Input[name=item] [ Value= ' Val '] "). attr (" Checked "," checked ");


if ($ ("Input[name=item][value= ' Val ']"). attr (' checked ') ==true)//judge whether it has been ticked


Radio Group Radio: $ ("Input[type=radio]"). attr ("Checked", ' 2′ ');//Set value=2 item as current selection


dropdown Box Select: $ ("#sel"). attr ("value", '-sel3′ ');//Set VALUE=-SEL3 item to current selection


$ ("<option value= ' 1′>1111</option><option value= ' 2′>2222</option>"). AppendTo ("#sel") Option
Adding a drop-down box

$ ("#sel"). empty ();//Empty Drop-down box





jquery gets Radio The value of the selected


Code $ ("Input[name= ' Radio_name '][checked]"). Val (); Select the value of the selected radio


$ ("#text_id"). focus (function () {//code ...}); Event triggers
When object text_id gets focus

$ ("#text_id"). blur (function () {//code ...}); Event triggers
When object text_id loses focus

$ ("#text_id"). Select (); Makes the Vlaue value of the text box selected


$ ("Input[name= ' radio_name '][value= ') to select the radio value '").


attr ("checked", true); Set Radio to selected based on value





jquery Gets the value value of the checkbox selection


$ ("Input[name= ' Checkbox_name '][checked]"); Select a collection of selected checkbox elements if you want the value you need to traverse this set


$ ($ ("Input[name= ' Checkbox_name '][checked]")).


each (function () {arrchk+=this.value + ', ';}); /traverse the set of selected checkbox elements to get value


$ ("#checkbox_id"). attr ("checked"); Gets the state of a checkbox (whether it is selected, returns True/false)


$ ("#checkbox_id"). attr ("Checked", true); Sets the status of a checkbox to checked (checked=true)


$ ("#checkbox_id"). attr ("checked", false); Sets the status of a checkbox to unchecked (Checked=false)


$ ("Input[name= ' Checkbox_name ')"). attr


("Checked", $ ("#checkbox_id"). attr ("checked");//According to 3,4,5, you can analyze the meaning of this code


$ ("#text_id"). Val (). Split (","); Returns the value of text to ', ' separated by an array


above these operations, in fact, is the use of jquery selector, I hope you have a solid knowledge of the jquery selector.

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.