Skip to content

Commit ba9abdd

Browse files
committed
doc: add <template> <textarea> tag document.
1 parent 89a8e7e commit ba9abdd

File tree

4 files changed

+167
-9
lines changed

4 files changed

+167
-9
lines changed

docs/tags/style.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ HTML \<style> Tag
8080

8181
## 相关页面
8282

83-
HTML tutorial: [HTML CSS](../tutorial/css.md)
83+
HTML 教程: [HTML CSS](../tutorial/css.md)
8484

8585
## 默认 CSS 设置
8686

docs/tags/td.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ HTML 表格有两种单元格:
137137
```
138138
<!--rehype:style=height: 110px;-->
139139

140-
How to vertical align content inside \<td> (with CSS):
140+
如何垂直对齐 \<td> 中的内容(使用 CSS):
141141

142142
```html idoc:preview:iframe
143143
<style>
@@ -156,7 +156,7 @@ How to vertical align content inside \<td> (with CSS):
156156
```
157157
<!--rehype:style=height: 150px;-->
158158

159-
How to set the width of a table cell (with CSS):
159+
如何设置表格单元格的宽度(使用 CSS):
160160

161161
```html idoc:preview:iframe
162162
<style>
@@ -175,7 +175,7 @@ How to set the width of a table cell (with CSS):
175175
```
176176
<!--rehype:style=height: 110px;-->
177177

178-
How to create table headers:
178+
如何创建表头:
179179

180180
```html idoc:preview:iframe
181181
<style>
@@ -196,7 +196,7 @@ How to create table headers:
196196
```
197197
<!--rehype:style=height: 160px;-->
198198

199-
How to create a table with a caption:
199+
如何创建带有标题的表格:
200200

201201
```html idoc:preview:iframe
202202
<style>

docs/tags/template.md

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,82 @@
1-
template.md
1+
HTML \<template> Tag
22
===
33

4-
欢迎您编辑 <a target="__blank" href="https://github.com/jaywcjlove/html-tutorial/blob/main/docs/tags/template.md">docs/tags/template.md</a> 文件,共建 HTML Tutorial 文档。
4+
## 示例
5+
6+
使用 \<template> 保存一些在页面加载时将被隐藏的内容。 使用 JavaScript 显示它:
7+
8+
```html idoc:preview:iframe
9+
<button onclick="showContent()">Show hidden content</button>
10+
<template>
11+
<h2>Flower</h2>
12+
<img src="../assets/example.png" width="214">
13+
</template>
14+
<script>
15+
function showContent() {
16+
var temp = document.getElementsByTagName("template")[0];
17+
var clon = temp.content.cloneNode(true);
18+
document.body.appendChild(clon);
19+
}
20+
</script>
21+
```
22+
23+
## 定义和用法
24+
25+
`<template>` 标签用作一个容器,用于在页面加载时保存一些对用户隐藏的 HTML 内容。
26+
27+
`<template>` 中的内容可以稍后使用 JavaScript 渲染。
28+
29+
如果您有一些 HTML 代码要反复使用,则可以使用 `<template>` 标记,但在您要求之前不要使用。 要做到这一点*没有* `<template>` 标记,您必须使用 JavaScript 创建 HTML 代码,以防止浏览器呈现代码。
30+
31+
## 浏览器支持
32+
33+
| Element | ![chrome][1] | ![edge][2] | ![firefox][3] | ![safari][4] | ![opera][5] |
34+
| ------- | --- | --- | --- | --- | --- |
35+
| \<template> | 26.0 | 13.0 | 22.0 | 8.0 | 15.0 |
36+
37+
## 全局属性
38+
39+
`<template>` 标签支持 HTML 中的[全局属性](../reference/standardattributes.md)
40+
41+
## 更多示例
42+
43+
用一个新的 div 元素为数组中的每个项目填充网页。 每个 div 元素的 HTML 代码都在模板元素内:
44+
45+
```html idoc:preview:iframe
46+
<button onclick="showContent()">Show hidden content</button>
47+
<template>
48+
<div class="myClass">I like: </div>
49+
</template>
50+
<script>
51+
var myArr = ["Audi", "BMW", "Ford", "Honda", "Jaguar", "Nissan"];
52+
function showContent() {
53+
var temp, item, a, i;
54+
temp = document.getElementsByTagName("template")[0];
55+
item = temp.content.querySelector("div");
56+
for (i = 0; i < myArr.length; i++) {
57+
a = document.importNode(item, true);
58+
a.textContent += myArr[i];
59+
document.body.appendChild(a);
60+
}
61+
}
62+
</script>
63+
```
64+
<!--rehype:style=height: 130px;-->
65+
66+
检查浏览器对 \<template> 的支持:
67+
68+
```html idoc:preview:iframe
69+
<script>
70+
if (document.createElement("template").content) {
71+
document.write("Your browser supports template!");
72+
} else {
73+
document.write("Your browser does not supports template!");
74+
}
75+
</script>
76+
```
77+
78+
[1]: ../assets/chrome.svg
79+
[2]: ../assets/edge.svg
80+
[3]: ../assets/firefox.svg
81+
[4]: ../assets/safari.svg
82+
[5]: ../assets/opera.svg

docs/tags/textarea.md

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,84 @@
1-
textarea.md
1+
HTML \<textarea> Tag
22
===
33

4-
欢迎您编辑 <a target="__blank" href="https://github.com/jaywcjlove/html-tutorial/blob/main/docs/tags/textarea.md">docs/tags/textarea.md</a> 文件,共建 HTML Tutorial 文档。
4+
## 示例
5+
6+
多行文本输入控件(文本区域):
7+
8+
```html idoc:preview:iframe
9+
<label for="review">评论:</label>
10+
<br>
11+
<textarea id="review" name="review" rows="4" cols="50">
12+
在 HTML Tutorial,您将学习如何制作网站。 他们提供所有 Web 开发技术的免费教程。
13+
</textarea>
14+
```
15+
16+
## 定义和用法
17+
18+
`<textarea>` 标签定义了一个多行文本输入控件。
19+
20+
`<textarea>` 元素通常在表单中使用,以收集用户输入,如评论或评论。
21+
22+
一个文本区域可以容纳无限数量的字符,并且文本以固定宽度的字体(通常是 Courier)呈现。
23+
24+
文本区域的大小由 `<cols>``<rows>` 属性(或使用 CSS)指定。
25+
26+
表单提交后需要name属性引用表单数据(如果省略name属性,则不会提交文本区域的数据)。
27+
28+
需要 `id` 属性将文本区域与标签相关联。
29+
30+
**提示:** 始终添加 [\<label>](./label.md) 标签以获得最佳可访问性实践!
31+
32+
## 浏览器支持
33+
34+
| Element | ![chrome][1] | ![edge][2] | ![firefox][3] | ![safari][4] | ![opera][5] |
35+
| ------- | --- | --- | --- | --- | --- |
36+
| \<textarea> | Yes | Yes | Yes | Yes | Yes |
37+
38+
## 属性 Attributes
39+
40+
| 属性 || 描述 |
41+
| ---- | ---- | ---- |
42+
| [autofocus](./textarea_autofocus.md) | autofocus | 指定在页面加载时文本区域应自动获得焦点 |
43+
| [cols](./textarea_cols.md) | *number* | 指定文本区域的可见宽度 |
44+
| [dirname](./textarea_dirname.md) | *textareaname*.dir | 指定将提交textarea的文本方向 |
45+
| [disabled](./textarea_disabled.md) | disabled | 指定应禁用文本区域 |
46+
| [form](./textarea_form.md) | *form\_id* | 指定文本区域属于哪个表单 |
47+
| [maxlength](./textarea_maxlength.md) | *number* | 指定文本区域中允许的最大字符数 |
48+
| [name](./textarea_name.md) | *text* | 指定文本区域的名称 |
49+
| [placeholder](./textarea_placeholder.md) | *text* | 指定描述文本区域预期值的简短提示 |
50+
| [readonly](./textarea_readonly.md) | readonly | 指定文本区域应该是只读的 |
51+
| [required](./textarea_required.md) | required | 指定需要/必须填写文本区域 |
52+
| [rows](./textarea_rows.md) | *number* | 指定文本区域中可见的行数 |
53+
| [wrap](./textarea_wrap.md) | hard soft | 指定在表单中提交时如何包装文本区域中的文本 |
54+
55+
## 全局属性
56+
57+
`<textarea>` 标签支持 HTML 中的[全局属性](../reference/standardattributes.md)
58+
59+
## 事件属性
60+
61+
`<textarea>` 标签支持 HTML 中的[事件属性](../reference/eventattributes.md)
62+
63+
## 更多示例
64+
65+
66+
禁用默认调整大小选项:
67+
68+
```html idoc:preview:iframe
69+
<style>
70+
textarea { resize: none; }
71+
</style>
72+
<label for="review">评论:</label>
73+
<br>
74+
<textarea id="review" name="review" rows="4" cols="50">
75+
在 HTML Tutorial,您将学习如何制作网站。 他们提供所有 Web 开发技术的免费教程。
76+
</textarea>
77+
```
78+
79+
80+
[1]: ../assets/chrome.svg
81+
[2]: ../assets/edge.svg
82+
[3]: ../assets/firefox.svg
83+
[4]: ../assets/safari.svg
84+
[5]: ../assets/opera.svg

0 commit comments

Comments
 (0)