禁用/只读 html 中的选择标签
我究竟如何才能将选择标签设为只读。我读到您不能将选择设置为只读。我这样做,我可以将其设置为禁用,但是......这不是一个选项。我希望用户查看选择标签中的其余选项,但无法选择其中之一..
有什么想法吗?
How exactly can I go about making a select tag readonly. I've read that you can't set a select as readonly. I do that I can set it as disabled but... That is not an option. I would like the user to view the rest of the options in the select tag, but not be able to pick one of them..
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以使用禁用属性。
例如。
you can use disabled attribute.
for example.
假设标签 id="mySelectID",并且 jQuery 是常驻的,那么:
assume that tag id="mySelectID", and jQuery is resident, then :
您可以通过添加
style="pointer-events:none;"
将其设置为假只读You can make it fake-readonly by adding
style="pointer-events:none;"
我使用了选项标记的选定禁用值。
它将起到提示用户选择一个选项并同时禁用该选项的目的。
例子:
I used the selected disabled values for the option tag.
It will serve the purpose of prompting the user to select an option and at the same time disabling that option.
Example:
https://coderanch.com/t/469173/select-box-READONLY-true
如果您想禁用选择框,那么您可以使用 JavaScript 代码在表单提交之前重新启用它。因此,在表单的onsubmit事件上,您可以启用选择框,以便在提交表单时也提交其值...
https://coderanch.com/t/469173/select-box-READONLY-true
if you want to disable the select box, then you can use a javascript code to enable it back before the form submits. So on the onsubmit event of the form, you can enable the select box so that its value is also submitted when the form is submitted...