jQuery operational input values are summarized
Gets the selected value
Gets a set of values radio selected items
var item = $(“input[@name=items]:checked”).val();
Get select items selected text
var item = $("select[@name=items] option[@selected]").text();
drop-down box to select the second value of the currently selected element
$('#select_id')[0].selectedIndex = 1;
The second element radio radio set for the currently selected value
$('input[@name=items]').get(1).checked = true;
Get the value:
Text boxes, text areas:
$("#txt").attr("value"); $("#txt").val();
Checkbox checkbox:
$("#checkbox_id").attr("value");
Radio group radio:
$("input[@type=radio][@checked]").val();
Drop-down box select:
$ ( '# Salt') val ().
Control form elements: text box, the text region:
$ ( "# Txt") attr ( "value", '');. // empty the contents $ ( "# Txt") attr ( "value", '11');. // filling contents
Checkbox checkbox:
$ ( "# Chk1") attr ( "checked", '');. // uncheck $("#chk2").attr("checked",true);//打勾 if ($ ( "# chk1"). attr ( 'checked') == undefined) // determine whether tick
Radio group radio:
$("input[@type=radio]").attr("checked",'2'); // set value = 2 project for the currently selected item
Drop-down box select:
. $ ( "# Sel") attr ( "value", '- sel3'); // set value = -sel3 the selected item to the current project $("<optionvalue='1'>1111</option><optionvalue='2'>2222</option>") .appendTo ( "# sel") // add a drop-down box option $ ( "# Sel") empty ();. // clear the drop-down box
In the Jquery with $ ( "# id") to get the input element on the page, which is equivalent to document.getElementById ( "element") However, this acquisition is a Jquery object rather than a subject .value is dom dom element attribute of the object element so that, using the $ ( "# id") value can not take the value, in the method as follows:
Value:
val = $("#id")[0].value; $("#id")[0].value = "new value";
Assignment:
$("#id")[0].value = "new value"; 或者$("#id").val("new value"); val = $("#id").attr("value");
Reproduced in: https: //www.cnblogs.com/oshoh/p/11034939.html