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

旧时模样 提交于 2019-12-10 11:23:49

问题


If I have an HTML input field like this one:

<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?

(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).


回答1:


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).



来源:https://stackoverflow.com/questions/4333919/how-to-hide-the-caret-in-an-html-text-input-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!