1

I have a form that uses javascript to populate a textarea with some text. The user should be able to copy the text, and I've used the code below to make the textarea readonly.

<textarea readonly id="newList" name="newList" placeholder="When you click 
 the button below, your list appears here.  Copy and paste it into your 
 new document. Use CTRL-A to quickly select all items."></textarea>

Works great in Chrome, but in IE10 the textarea is STILL not readonly, and when a user clicks in it the text that they want to copy disappears, replaced by the cursor. It has nothing to do with my javascript -- I removed the "script" line from my HTML and this still happens.

Is there an easy way to make a textarea readonly in Internet Explorer?

4

2 回答 2

1

我正在 IE10 中尝试该确切代码,并且 textarea 是只读的,但是当您单击它时,占位符文本会消失。我相信这是 IE 的正常行为。您是否将需要复制的文本放在占位符属性中?如果是这样,那就是问题所在。

包含需要复制的文本的 textarea 应如下所示:

<textarea readonly id="newList" name="newList">Text that needs to be copied...</textarea>

它也可以添加占位符属性,但占位符属性中指定的文本将不再显示。

另请注意,如果您使用 disabled 属性,您将无法复制 textarea 中的文本。

于 2013-11-14T20:21:24.203 回答
1

您可以禁用您的 textarea,但这不仅会阻止它可编辑,而且意味着它不会在提交时发送 - 所以如果这是一个好主意,这取决于您想如何使用它。

您可以将 onFocus() 事件添加到您的文本区域,以便在用户点击进入文本区域时将其移出文本区域。

于 2013-11-14T20:06:39.757 回答