Jquery method to get element values of common form elements


Jquery radio value, checkbox value, select value, radio select, checkbox select, select, and so on Gets the values of a set of selected items of radio Var item = $(’ input [name = items] [checked] ’). The val (); Gets the text of the selected item in a select Var item = $(“select[name=items] option[selected]“).text(); The second element of the select drop-down box is the currently selected value $(’ # select_id) [0]. SelectedIndex = 1; The second element of the radio radio group is the currently selected value [name = $(’ input items] ’). The get (1) checked = true;

Get the value:

Text field: $(”# TXT “).attr(“value”); $(“#checkbox_id”).attr(“value”); Radio set radio: $(” input [@ type = radio] [@ checked] ”). The val (); Select: $(‘#sel’).val();

Control form elements: Text field: $(”# TXT “).attr(“value”, ”); // empty the content $(” # TXT ”). Attr (” value ”, “11”); // fill in the content

$(“#chk1”).attr(“checked”, ”); / / no box $(” # chk2). Attr (” checked ”, true); / / box If ($(” # chk1 ”). The attr (” checked ”) = = undefined) / / determine whether have tick

Radio set radio: $(” input [@ type = radio] ”). The attr (” checked ”, ‘2’); // the item with value=2 is the currently selected item Select: $(“#sel”).attr(“value”,‘-sel3’); // the item with value=-sel3 is the currently selected item $(” < The option value = ‘1’ > 1111 < / option> < The option value = ‘2’ > 2222 < / option>” ). AppendTo (“#sel”)// add options to the drop-down box $(” # sel ”). The empty (); // empty the drop-down box