- var selid = document.getelementbyid (" Sltid ");
-
- for (var i= 0; i<10;i++) { //Loop adds multiple values
-
- sid.option[i] = new option (i,i);
-
- }
-
- Sid.options[sid.options.length]=new option ("1", "2"); // add one more after the last value
Jquery:
[HTML]View Plaincopy
- <select id="AA"></Select>
- 1.jQuery ("<option value=' 1 '>abc</option>"). AppendTo ("#aa");
- 2.jQuery ("<option></option>"). attr ({val: "1", Text: "ABC"}). AppendTo ("# AA ");
- 3.jQuery ("<option></option>"). val ("1"). Text ("abc"). AppendTo ("#aa");
- 4.$ ("#selectId"). Append ("<option value='" +value+ "'>" +text+ "</option > ");
Of course, in addition to these words, but also set the default selection value, the first value, the last value, the nth value and so on, so on the internet searched:
jquery Gets the text and value selected by select:
[HTML]View Plaincopy < param name= "wmode" value= "Transparent" >
- $ ("#select_id"). Change (function () {//code ...}); Add an event for Select, which is triggered when one of the items is selected
- var checktext=$ ("#select_id"). Find ("option:selected"). Text (); Gets the text selected by the Select
- var checkvalue=$ ("#select_id"). Val (); Gets the value selected by Select
- var checkindex=$ ("#select_id"). Get (0). SelectedIndex; Gets the index value of the select selection
- var maxindex=$ ("#select_id option:last"). attr ("index"); Gets the maximum index value of the Select
jquery Add/Remove option for select:
[HTML]View Plaincopy
- 1. $ ("#select_id"). Append ("<option value=' value '>text</option>"); Append an option to the Select ( drop-down item)
- 2. $ ("#select_id"). Prepend ("<option value=' 0 '> Please select </option>"); Insert an option for select (first position)
- 3. $ ("#select_id option:last"). Remove (); Delete index value in select maximum option (last)
- 4. $ ("#select_id option[index=' 0 ')". Remove (); Delete option with index value 0 in select (first)
- 5. $ ("#select_id option[value=' 3 ')". Remove (); Delete option for value= ' 3 ' in select
- 5. $ ("#select_id option[text=' 4 ')". Remove (); Delete option for text= ' 4 ' in select
JS, jquery, dynamic add Option Item