有一个不可编辑的,但可选择的文本框 [英] Having an uneditable, but selectable textbox

查看:423
本文介绍了有一个不可编辑的,但可选择的文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做一个web应用程序。在这里面有些时候一种形式可能是只读。要使用HTML模拟这一点,我有这样所有的(动态创建的)的文本包含内容框被禁用。这工作正常足够了,但如果有非常多的文字,而不是所有的它是可见的一次(特别是在多行框),然后不存在用于用户在其左右滚动的方式。此外,另一个问题是它不可能从文本禁用文本框复制和粘贴。

I'm making a web app. In it there are times when a form may be "read only". To simulate this with HTML, I have it so that all the (dynamically created) text boxes that contain content are disabled. This works fine enough, but if there is very much text and not all of it is visible at once(especially in multi-line boxes) then there isn't a way for the user to scroll around in it. Also, another issue is its not possible to copy and paste text from disabled text boxes.

那么,我需要一种方法来使,所以你不能修改文本框的内容,但你可以选择文本和滚动条的作品。

So what I am needing is a way to make it so you can not modify the content in a textbox, but you can select the text, and the scroll bar works.

另外,我在Firefox 3.5测试这一点,虽然我认为IE浏览器有类似的问题。(兼容东西既请)

Also, I'm testing this in Firefox 3.5, though I believe IE has similar problems.(something compatible with both please)

推荐答案

使用JS:

<输入类型=文本只读=只读的onfocus =this.blur(); />

<input type="text" readonly="readonly" onfocus="this.blur();" />

此外,也许会让一个可滚动的div呢?(溢出:汽车;在CSS)

Also, perhaps make a scrollable div instead (overflow:auto; in CSS)?

这篇关于有一个不可编辑的,但可选择的文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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