I can't find any solution to simple value change in select, code works corretly in Chrome and in IE but doesn't work in FF
<select id='testsel' name='test'>
<option value="">-- select something --</option>
<option value="1">selected</option>
</select>
and if I try
$('#testsel').val("1");
value is selected but not displayed (you can see if you expand select). What is strange
$('#testsel').val();
returns "" (first value)
Same pr开发者_运维技巧oblem if I try
$('#testsel > option[value="1"]').attr("selected", "selected");
but this time result is bit different
$('#testsel > option[value="1"]').attr("selected");
I see "selected" as a result, but on screen nothing.
Any idea?
Are you using some styling plugin for the select ?
Usually those plugins will replace the element, and altering the values through code will not reflect on the replaced element. (although i find it strange that it does work on other browsers)
For normal elements your example code should work (as verified in the comments).
精彩评论