![](/img/trans.png)
[英]Make input field readonly without changing background colour in CSS or JavaScript
[英]Use readonly attribute in <input> without changing the cursor
如果我有一个带有readonly
属性的<input>
字段,它仍会出现在工readonly
文本光标中。 有没有办法阻止光标显示?
我无法使用disabled
属性,因为request.getParameter()
不适用于禁用的字段。
readonly
元素的想法是你仍然可以阅读和复制文本,而不是编辑它们。 也就是说,您可以使用CSS属性选择器更改光标。 此示例将使用readonly
属性匹配任何input
元素:
input[readonly] {
cursor: pointer;
}
我不想覆盖bootstrap的默认样式,所以我提出了以下解决方案:
我的文件:
input[readonly] {
&.default-cursor {
cursor: default;
}
}
或者在CSS中:
input[readonly].default-cursor {
cursor: default;
}
我的HTML:
<input type="text" class="form-control text-xl default-cursor" readonly>
在表单中尝试使用此标记作为文本字段
<input type="text" value="test" onfocus="this.blur()" readonly="readonly" />
帮助你隐藏光标的主要内容是onfocus =“this.blur()”。
对于那些不想让插入符号显示的人:
input[readonly] {
pointer-events: none;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.