Common Operations of javascript jquery on form elements, jqueryform
1.Drop-down box select:
Remove option
$("#ID option").each(function(){ if($(this).val() == 111){ $(this).remove(); }});
Add option
$("<option value='111'>UPS Ground</option>").appendTo($("#ID"));
Obtain the selected value from the drop-down list.
// Obtain the text $ ('# testSelect option: selected') from the drop-down list '). text (); $ ("# testSelect "). find ('option: selected '). text (); document. all. objSelect. options [document. all. objSelect. selectedIndex]. text; // js operation objSelect: select name // get the drop-down select value $ ("# testSelect "). val (); // js Operation document. getElementById ('objselect '). value = 2; document. all. objSelect. value;
Select the drop-down Box Based on the option value
$ ('# Testselect '). val ('20140901'); document. all. objSelect. value = objItemValue; // js operation objSelect is the name or iddocument of select. getElementById ('sel '). value = objItemValue;
The second element in the select drop-down box is the selected value.
$('#select_id')[0].selectedIndex = 1;
2,Single-sector radio:
$ ("Input [type = radio] [checked]"). val (); // obtain the value of the selected items in a single sequence (note that there is no space in the middle) $ (': radio [name = "radio"]: checked '). val (); // method 2 $ ("input [type = radio] [value = 2]"). attr ("checked", 'checked'); // set single checked value = 2 to the selected status. (Note that there is no space in the middle) $ (': radio [value = "2"]'). attr ('checked', 'checked ');
The second element of the radio Group is the currently selected value.
$("input[name='items']").get(1).checked = true;
3,Check box checkbox(For other writing methods, see the above: radio)
$ ("Input [type = 'checkbox'] [checked]"). val (); // obtain the value of the first check box $ ("# chk1 "). attr ("checked", ''); // do not tick $ (" # chk2 "). attr ("checked", true); // tick // select all/do not select $ ("# selectAll "). bind ('click', function () {var sa = $ (this ). attr ("checked"); $ ("input [name = 'sel [] ']"). each (function () {this. checked = sa ;});});
4. input:
$ (': Input [name = "keyword"]'). val (); // obtain the value based on the name value
5, Text box textarea:
Fixed text box size: <textarea name = "123" style = "resize: none;"> </textarea>
The common operations of javascript jquery on form elements described above are all the content shared by the editor. I hope to give you a reference, and I hope you can provide more support to the customer's house.