Simple implementation of jQuery to get multiple input values

  • 2021-06-29 09:47:04
  • OfStack

Gets whether the checked value of input is true:

Type 1:

if ($("input[name=item][value='val']).attr ('checked') ==true) //Determine if a check has been made--Note: name is the control name property, value is the control value property

Type 2:

Attribute values may not be specified, since a set of checkbox value values will all save their corresponding id in the database, it is best to write as follows:

if($("input[name=row_checkbox]").attr('checked')==true)

Type 3:

if ($("[name=row_checkbox] ").attr('checked') ==true) --Note: name is the control name property

jquery radio, checkbox, select, radio, checkbox, select, and related article categories: Web Front End:

radio:

Gets the value of a selected set of radio items: var item = $('input [name=items][checked]'). val(); --Note: name is the control name property

The second element in the radio radio group is the current selection: $('input [@name=items]'). get(1). checked = true;

Or $('input [name=items]'). attr ('checked','1');

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

radio sets the element value=2 as the currently selected item: $("input[type=radio]").attr("checked",'2');

value value for radio selected item: $("input[name='radio_name'][checked]'.val();

Set Radio as selected according to Value value: $("input[name='radio_name'][value='The Value value of Radio to be selected''). attr('checked', true);

select:

Gets the text of the selected item for select: 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 id property of the control

The element of select drop-down box value ='val'is currently selected: $("select [name=items] option [value='val']). attr ("selected","selected");

select sets value=-sel3 as the currently selected item: $("#sel"). attr ("value",'-sel3'); -Note: sel is the id property of the select control

Add option: $(" < option value='1' > 1111 < /option > < option value='2' > 2222 < /option > ").appendTo("#sel");

select Empty: $("#sel"). empty();

checkbox:

The second element of checkbox is checked: $("input [name=items]").get(1).checked = true;//tick

value='val'of checkbox checks: $("input [name=item] [value='val']). attr ("checked, true");

Or $("input[name=item][value='val']). attr ("checked","checked");

To determine if checkbox has been checked: if ($("input [name=item] [value='val']). attr ('checked')==true)

jQuery obtains the Value value selected by CheckBox:

//Select the set of selected CheckBox elements You need to traverse this set if you want to get the Value value

$($("input[name='checkbox_name'][checked]")).each(function(){

arrChk+=this.value+',';//Traverse the set of selected CheckBox elements to get the Value value

});

checked property of checkbox:

$("#checkbox_id'). attr ('checked'); //Gets the status of an CheckBox (if unchecked, returns true/false)

$("#checkbox_id "). attr (" checked ", true); //Set the status of an CheckBox to checked (checked=true)

$("#checkbox_id "). attr (" checked ", false); //Set the status of an CheckBox to unchecked (checked=false)

//Analyse the meaning of this code according to the above 3:

$("input[name='checkbox_name']").attr("checked",$("#checkbox_id").attr("checked"));

--Note: According to control checkbox_checked state of id is name='checkbox_name's input assigns the same checked state

Get value:

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

Multiple check box checkbox: $("input [name='checkbox': checked]). each (function(){

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

};

Radio group radio: $("input[type=radio][checked]"). val();

The value value of the drop-down box select: $('select'). val();

The value of text selected in the drop-down box select: $("select"). find ("option:selected"). text();

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

$("#txt"). attr ("value",'11'); //Fill in content

Event:

When object text_Triggered when id gets focus: $("#text_id "). focus (function(){//code...});

When object text_Triggered when id loses focus: $("#text_id "). blur (function(){//code...});

Other:

Make the Vlaue value of the text box checked: $("#text_id "). select();

$("#text_id "). val (). split (");//Returns an array separated by','with the Value value of Text


Related articles: