从聚焦的只读输入中删除文本插入符号/指针
我正在使用 (样式为普通文本)来删除交互式字段的外观,但仍显示该值。
这对于防止用户编辑字段非常有用,同时仍然能够发布值。我意识到这是一种方便的方法,并且有多种解决方法,但我想使用这种方法。
问题:当单击/聚焦字段时,闪烁的插入符号仍然出现。 (至少在 Win7 上的 FF 和 IE8 中)
理想情况下,我希望它像平常一样运行,可聚焦,但没有闪烁的插入符号。
欢迎使用 JavaScript 解决方案。
I am using an <input readonly="readonly">
, styled as normal text to remove the appearance of an interactive field, but still display the value.
This is very useful to prevent a user from editing a field, while still being able to post the value. I realize this is a convenience method and that there are several workarounds, but I want to use this method.
Problem: The blinking caret still appears when the field is clicked/focused. (At least in FF and IE8 on Win7)
Ideally, I would like it to behave as it normally does, focusable, but without the blinking caret.
Javascript solutions welcome.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
在我的上没有插入符号左右:
看看这个:http://www.cs。 tut.fi/~jkorpela/forms/readonly.html
抱歉,现在我明白你的问题了。
试试这个:
On mine there is no caret or so:
Take a look at this: http://www.cs.tut.fi/~jkorpela/forms/readonly.html
Sorry, now I understand your problem.
Try this:
您可以在 css 中使用它,但它不会聚焦:
You can use this in your css, but it will not focus:
您可以通过将 css 属性指定为 transparent 来删除闪烁的插入符,
您可以测试结果 此处
You can remove the blinking caret by specify the css attribute into transparent
you can test the result here
可以使用 html 和 javascript
或 jQuery来完成
It can be done using html and javascript
or jQuery
我找到的唯一方法是
the only way i found for this was
onfocus/blur 方法可以很好地从只读字段中删除光标,但浏览器不会自动重新聚焦到下一个字段,并且您可能会完全失去焦点,这不是用户通常所期望的。因此,如果需要,您可以使用纯 JavaScript 来关注您想要的下一个字段,但您必须指定下一个字段:
其中“NextField”是要转到的字段的名称。 (或者,您可以提供一些其他方法来定位下一个字段)。显然,如果您想要导航到某些不可见的 UI 元素(例如选项卡面板),这会更加复杂,因为您也需要对此进行安排。
The onfocus/blur method works ok to remove the cursor from a readonly field, but the browser does not automatically refocus on the next field, and you may lose focus altogether, which is not what the user usually expects. So, if this is required, you can use plain javascript to focus on the next field you want, but you have to specify the next field:
Where 'NextField' is the name of the field to goto. (Alternatively, you could provide some other means to locate the next field). Obviously, this is more involved if you want to navigate to some non-visible UI element, like a tab-panel, as you will need to arrange this as well.
简单!
只需在输入中添加
disabled
,它将不可点击(聚焦)Easy!
Just add
disabled
to input and it will not be clickable (focused)