Gets the text selected by select:
| The code is as follows |
Copy Code |
| $ ("#ddlregtype"). Find ("option:selected"). Text (); |
Gets the value selected by select:
| The code is as follows |
Copy Code |
| $ ("#ddlregtype"). Val (); |
Gets the index selected by select:
| The code is as follows |
Copy Code |
| $ ("#ddlregtype"). Get (0). SelectedIndex; |
Set Select:
Set the index selected by select:
| The code is as follows |
Copy Code |
| $ ("#ddlregtype"). Get (0). Selectedindex=index;//index is the index value |
Set the value selected by select:
| The code is as follows |
Copy Code |
$ ("#ddlregtype"). attr ("value", "normal"); $ ("#ddlregtype"). Val ("normal"); $ ("#ddlregtype"). Get (0). value = value; |
Set selected text for select:
The
| code is as follows |
copy code |
| var count=$ ("#ddlregtype option"). Length; for (var i=0;i<count;i++) { if ($ ("#ddlregtype"). Get (0). Options[i].text = text) { $ ("#ddlregtype" ). Get (0). options[i].selected = true; break; } } |
$ ("#select_id option[text= ' jquery ']"). attr ("selected", true);
To set the SELECT option item:
| The code is as follows |
Copy Code |
$ ("#select_id"). Append ("<option value= ' value ' >text</option>"); Add an option $ ("#select_id"). Prepend ("<option value= ' 0 ' > Please select </option>"); Insert an option before $ ("#select_id option:last"). Remove (); Delete the maximum index value option $ ("#select_id option[index= ']"). Remove ()//delete option with index value of 0 $ ("#select_id option[value= ' 3 ']"). Remove (); Delete option with a value of 3 $ ("#select_id option[text= ' 4 ']"). Remove (); Delete option with text value of 4 |
Empty select:
$ ("#ddlregtype"). empty ();
How do I get the value from the left selection box to the right selection box? I think I want to use the web effects can get, here with the more popular jquery.
The JS code is as follows:
// Get all property values var item = $ ("#select1"). Val ();
| The code is as follows |
Copy Code |
$ (function () { $ (' #select1 '). each (//get all the values of the Select1 function () { $ (' button '). Click (function () { Alert ($ (' #select2 '). Val ()); Get the Select1 value in Select2 }); });
}) |
</script>
It's worth noting that you can't write directly
| The code is as follows |
Copy Code |
$ (function () { $(' #select2 '). each (//) gets all the values for Select1 because the preceding option is added to the right from the left, and jquery does not actually pass the value from the left to the right. function () { $ (' button '). Click (function () { Alert ($ (this). Val ()); Get the Select1 value in Select2 }); });
}) |
Html:
| The code is as follows |
Copy Code |
<div class= "Centent" > <select multiple= "multiple" id= "Select1" name= "dd" style= "width:100px;height:160px"; > <option value= "1" > Option 1</option> <option value= "2" > Option 2</option> <option value= "3" > Option 3</option> <option value= "4" > Option 4</option> <option value= "5" > Option 5</option> <option value= "6" > Option 6</option> <option value= "7" > Option 7</option> </select> <div> <span id= "Add" > select Add to Right >></span> <span id= "Add_all" > All add to Right >></span> </div> </div> <div class= "Centent" > <select multiple= "multiple" id= "Select2" name= "sel" style= "width:100px;height:160px"; >
</select> <div> <span id= "Remove" ><< select Remove to left </span> <span id= "Remove_all" ><< all deleted to left </span> </div> </div> |