我的select
选项没有value
属性
<select id='1'>
<option>Label1</option>
<option>Label2</option>
</select>
我知道如何按值设置:
$("#1").val("whatever");
<小时/>
如何通过innerHTML设置选项?
我试过了
$("#1").html("Label1");
最佳答案
您仍然可以使用 .val()
设置它:
$("#1").val("Label2");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<select id='1'>
<option>Label1</option>
<option>Label2</option>
</select>
关于javascript - 如何通过innerHTML设置选择标签选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28076697/