HTML textarea readonly 属性

htmlweb developmentfront end technology更新于 2025/8/28 8:44:17

<textarea> 元素的 readonly 属性用于将文本区域设置为只读。如果文本区域设置为只读,访问者将无法更改其中的文本。

但是,访问者可以复制该内容。

以下是语法 −

<textarea readonly>

现在让我们看一个实现 <textarea> 元素 readonly 属性的示例 −

示例

<!DOCTYPE html>
<html>
<body>
<h2>Interview Questions</h2>
<p>Q1</p>
   <textarea rows="6" cols="70" placeholder="Why do you want go for the Editor Job Profile? (100 words)">
   </textarea>
   <p>Q2</p>
   <textarea rows="6" cols="70" placeholder="Do you have any previous publishing experience? (100 words)">
   </textarea>
   <p>Guidelines to appear for interview:</p>
   <textarea rows="6" cols="70" readonly>
      The interviewee should reach at 10AM with the certificates.
   </textarea>
</body>
</html>

输出

在上面的例子中,我们有 3 个文本区域 −

<p>Q1</p>
<textarea rows="6" cols="70" placeholder="Why do you want go for the Editor Job Profile? (100 words)">
</textarea>
<p>Q2</p>
<textarea rows="6" cols="70" placeholder="Do you have any previous publishing experience? (100 words)">
</textarea>
<p>Guidelines to appear for interview:</p>
<textarea rows="6" cols="70" readonly>
   The interviewee should reach at 10AM with the certificates.
</textarea>

其中一个文本区域被设置为只读,因此用户无法在其中添加任何文本 −

<textarea rows="6" cols="70" readonly>
   The interviewee should reach at 10AM with the certificates.
</textarea>

相关文章


有用资源