How to re-select something in a <select> element using jQuery?
Using jQuery, what is the most simple and elegant way to re-select an item in a <select>
dropdown list when given chosen_value=111?
What if it is checkboxes instead of <select>
, having id[]=11&id[]=12
... (the [] are actually in %5B开发者_StackOverflow社区%5D)
For the dropdownlist, just set the value using the val() function.
$("#mySelect").val(chosen_value);
For the checkboxes, you can set all the values at once if you can get the array of checkbox names that should be checked.
$("input[type=checkbox]").val(["checkbox1", "checkbox3", "checkbox4"]);
精彩评论