在输入字段中选择文本,但禁用编辑 [英] Select the text in the input field, but the editing is disabled

查看:73
本文介绍了在输入字段中选择文本,但禁用编辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的txt输入字段:

I have a simple txt input field:

< input type =textname =value =http:/ /google.com/>

如果我在输入内部单击,我想选择文本。这部分没问题:

If i click inside the input, i want to select the text. This part is fine with this:


$('input.highlight')。click(function(){

$('input.highlight').click(function(){

$(this).focus()。select();

$(this).focus().select();

返回false;

});

但是,我也要禁用编辑功能。如果我把假回报;到keydown事件,ctrl + c不起作用。如果我将disabled =disabled设置为输入,则select不起作用。

But, i want to disable the editing also. If i put a return false; to the keydown event, the ctrl+c is not working. If i put disabled="disabled" to the input, the select is not working.

有什么想法吗?谢谢。

推荐答案

您想要添加 readonly 属性而不是已禁用

You want to add the readonly attribute instead of disabled:

<input type="text" name="" readonly="readonly" value="http://google.com" />

这篇关于在输入字段中选择文本,但禁用编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆