Use Jquery to alter an item in a selectlist?
Before:
<select id="NumberId" name="NumberId">
<option value="">ZERO</option>
<option value="4">FOUR</option>
<option value="5">FIVE</option>
</select>
Using JQuery, modify the value of the option with an empty value to 0 (zero).
After:
<select id="NumberId" name="NumberId">
<option value="0">ZERO</option>
<option value="4">FOUR</option>
<option value="5">FIVE</option>
</select>开发者_如何学Python
How can I do that?
I think you can do something like:
$("#NumberId option[value='']").val('0');
good luck
Well you can do something like this:
$("#NumberId option[value='']").attr("value", "0");
or
$("#NumberId option[value='']").val("0");
(not 100% sure that works with <option>
elements)
But the more obvious thing to do is correctly generate the HTML on the serverside, no?
$("select option[value='']").attr("value", "0");
精彩评论