[英]html select default
In the html tag, is there something like 在html标记中,是否有类似
<select default="someValue" ... >
or 要么
to specify the value being selected when the page is loaded? 指定在加载页面时选择的值? I don't have access to the single options, so
我无权使用单个选项,因此
<option value="" selected> ...
does not work for me. 对我不起作用。
<option value="something" selected="selected">
Is the only html way. 是唯一的html方式。 But you can do this with jQuery , eg give your select an ID
<select id="mySelect">
但是您可以使用jQuery完成此操作,例如,给您的选择一个ID
<select id="mySelect">
and 和
$(document).ready(function() {
$("#mySelect option[value='someValue']").attr('selected', 'selected');
});
If you don't want to use jQuery, there also is a plain javascript solution 如果您不想使用jQuery,也可以使用普通的javascript解决方案
<select id="Select1" >
<option value="x" selected="selected">x</option>
<option value="y">Y</option>
</select>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.