jquery gets the input value in various cases

Source: Internet
Author: User

Gets whether the checked value of input is true:

The first type:

if ($ ("Input[name=item][value= ' Val ')"). attr (' checked ') ==true)//Determine if it has been ticked-note: name is the control Name property, value is the control's Value property

The second type: You can not specify a property value, because the value of a set of checkboxes will hold its corresponding ID in the database, preferably written as follows:if ($ ("Input[name=row_checkbox]"). attr (' checked ') ==true)The third type:if ($ ("[Name=row_checkbox]"). attr (' checked ') ==true)--Note: name is the control Name propertyjquery Radio value, checkbox value, select Value, Radio selected, CheckBox selected, select selected, and related article Category: Web Front end:Radio:Gets the value of a set of radio selected items: var item = $ (' input[name=items][checked] '). Val ();                                                     --Note: name is the control Name property Radio The second element of the radio group is the currently selected item: $ (' input[@name =items] '). Get (1). checked = true; or $ (' input[name=items] '). attr ("Checked", ' 1′ '); radio's value = ' val ' element is currently selected: $ (' input[name=items] [value= ' V Al '] '). attr ("Checked", "checked"); Radio sets the element of the value=2 as the currently selected item: $ ("Input[type=radio"). attr ("Checked", ' 2′ '); Radio the value of the selected item: $ ("input[name= ' Radio_name '][checked]"). Val (); Set Radio as selected based on value: $ ("input[name= ' Radio_name ') [value= ' To select Radio Value ' "). attr (" Checked ", true);Select:Gets the text of the Select selected item: var item = $ ("select[@name =items] option[@selected]"). Text (); or var item = $ ("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; --Note: select_id ' is the control's ID property Select dropdown box value = ' val ' element is currently selected: $ ("Select[name=items] option[value= ' Val ']"). attr ("Selected"    , "selected"); Select sets the VALUE=-SEL3 item as the currently selected item: $ ("#sel"). attr ("value", '-sel3′ '); --Note: SEL is the ID property of the Select control to add the drop-down box of the option:$ ("<option value= ' 1′>1111</option><option value= ' 2′>2222< /option> "). AppendTo (" #sel "); Select empty: $ (" #sel "). empty ();checkbox:The second element of the checkbox is ticked: $ ("Input[name=items]"). Get (1). checked = true;  //tick checkbox value= ' val ' element tick: $ (" Input[name=item][value= ' Val '] "). attr (" Checked ", true);                                                    or $ ("Input[name=item][value= ' Val ')"). attr ("Checked", "checked"); Determine if the checkbox has been ticked: if ($ ("input[ Name=item][value= ' Val '). attr (' checked ') ==true)  jquery Gets the value values of the checkbox selection://Select the collection of selected checkbox elements If you want value values you need to traverse this set $ ($ ("Input[name= ' Checkbox_name '][checked]")). each (function () {arrchk+=this.value + ', ';    //Traverse the collection of selected checkbox elements to get value});  checkbox's Checked property: $ ("#checkbox_id"). attr ("checked"); Gets the status of a checkbox (there is no selected, returns True/false) $ ("#checkbox_id"). attr ("Checked", true); Sets the status of a checkbox to be checked (checked=true) $ ("#checkbox_id"). attr ("CHecked ", false); Set a checkbox with a status of unchecked (Checked=false)//According to the above three, analyze and analyze the meaning of this code: $ ("input[name= ' Checkbox_name ')"). attr ("Checked", $ ("# checkbox_id "). attr (" checked "));--note: The checked status for Name= ' Checkbox_name ' is assigned the same checked status according to the checkbox_id of the control,     Get Value:text box, text area: $ ("#txt"). attr ("value"), Multi-marquee checkbox:$ ("Input[name= ' checkbox ': Checked]"). each (function () {var val = $ (thi          s). Val (); }), Radio group radio:$ ("input[type=radio][checked]"). Val (); Drop-down box select value: $ (' select '). val (); Drop-down box select the text value selected: $ (" Select "). Find (" option:selected "). Text (); textbox, Text area: $ (" #txt "). attr (" value ","); Empty content $ ("#txt"). attr ("value", ' 11′ '); Populating contentEvent:triggered when the object text_id gets focus: $ ("#text_id"). focus (function () {//code ...}); triggered when the object text_id loses focus: $ ("#text_id"). blur (function () {//code ...});Other:Make the Vlaue value of the text box selected: $ ("#text_id"). Select (); $ ("#text_id"). Val (). Split (","); Returns an array of value values of text as ', ' delimited

jquery gets the input value in various cases

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.