HTML<选项>标签 。如何选择一个值?选项>
任何人都可以帮助我解决这个问题..
我有一个像这样的选项框,
<select name="facility_info_input[facility_type_id]" id="facility_type_id">
<option value=1 >Room</option>
<option value=2 >Equipment</option>
</select>
我想根据变量值自动选择上述选项之一(在用户填写/更新表单之前,应该已经选择了该选项), 作为一个例子,我有一个数据变量(从数据库读取),它的值为 1 /2 ,如果它的 1 可以自动选择这个“房间”选项, 我一直在尝试使用 selected="selected" 属性,但仍然不知道如何使用它,他们还有其他方式吗?
先感谢您..
Can any one help me with this..
i have an option box like this
<select name="facility_info_input[facility_type_id]" id="facility_type_id">
<option value=1 >Room</option>
<option value=2 >Equipment</option>
</select>
i want to select one of the above options automatically according to the variable value(before user filling/updating the form the option should be already selected),
As an example i have a data variable(read from the database) and its value is 1 /2 , if its 1 can this "Room" option automatically selected,
I have been trying to use selected="selected" attribute, but still I couldn't figure it out how to use it,is their a any other way?
Thank you in advance..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将
selected="selected"
添加到您希望默认选择的选项。我假设你正在做这个服务器端。另外,您需要将属性用引号引起来。这可能就是您的代码无法正常工作的原因。
Add
selected="selected"
to the option you want selected by default. I am assuming you are doing this server side.Also, you need to enclose your attributes in quotation marks. This may be why your code wasn't working.