简体   繁体   English

如何在HTML文本输入字段中隐藏插入符号?

[英]How to hide the caret in an HTML text input field?

If I have an HTML input field like this one: 如果我有这样的HTML输入字段:

<input type="text" id="mytextfield"/>

all browsers seem to show the caret (insertion point) in the field. 所有浏览器似乎都在该字段中显示插入符号(插入点)。 Is is possible to prevent this from appearing by applying some CSS or javascript? 是否可以通过应用一些CSS或JavaScript来防止这种情况出现?

(My reason for asking is that my input is the basis of a GWT-Ext combo box like the ones on http://www.gwt-ext.com/demo/#linkedComboBox - you can't type in it, but you can still see the caret, which is annoying). (我问的原因是,我的输入是GWT-Ext组合框的基础,例如http://www.gwt-ext.com/demo/#linkedComboBox上的组合框-您无法输入,但您可以仍然可以看到插入符号,这很烦人。

What you could try is disable the input element and explicitly set its color to black: 您可以尝试禁用输入元素并将其颜色显式设置为黑色:

<input type="text" disabled="disabled" style="color: black;" ... />

This should work for the GWT-Ext combo box (at least it did when setting the attributes in firebug). 这应该适用于GWT-Ext组合框(至少在Firebug中设置属性时确实如此)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM