简体   繁体   English

启用输入选择但禁用文本输入

[英]Enable input selection but disable text entry

I'm wondering if there is a way to allow a form to be selected (clicked) but at the same time make the form unable to have text entered. 我想知道是否有一种方法可以选择(单击)表单,但同时又使表单无法输入文本。

I've tried using readonly which gave me the functionality but the cursor it provides is the same as if I set disabled=true and it greys out the input field which is confusing for the user. 我试过使用readonly ,它为我提供了功能,但它提供的游标与我设置disabled=true相同,并且它使输入字段变灰,这会使用户感到困惑。 Is there any alternatives? 还有其他选择吗?

<input class="notype" />

$('.notype').on('keydown', function(e){
    e.preventDefault();
})

What you haven't told us is why. 您没有告诉我们的是为什么。 If it's because you want it to be copied to clipboard but not changed, the above won't let you do that, if so please elaborate. 如果是因为您希望将其复制到剪贴板但不更改,则上面的内容将不允许您这样做,请详细说明。

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

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