Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zh-CN: update Glossary/Attribute #22604

Merged
merged 2 commits into from
Jul 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions files/zh-cn/glossary/attribute/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,16 @@
title: 属性(Attribute)
slug: Glossary/Attribute
l10n:
sourceCommit: ada5fa5ef15eadd44b549ecf906423b4a2092f34
sourceCommit: 26635ef6b1a40e538501bd81fdcf98725e14e6ea
---

{{GlossarySidebar}}

**属性**(Attribute)可扩展 HTML 或 XML {{Glossary("element", "元素")}},改变其行为或提供元数据。
**属性**(Attribute)可扩展 {{Glossary("HTML")}}{{Glossary("XML")}} {{Glossary("element", "元素")}},改变其行为或提供元数据。

属性的形式总是 `name="value"`(属性的标识符后跟相关的值)。
属性的形式总是 `name="value"`(属性的标识符后跟相关的值)。你可能会看到没有等号或值的属性。这是在 HTML 中提供空字符串。但是,在 XML 中这是无效的:XML 要求所有属性都有显式值。

你可能会看到没有等号或值的属性。这是在 HTML 中提供空字符串或在 XML 中提供属性名称的简写。

```html
<input required />
<!-- 等同于 -->
<input required="" />
<!-- 或 -->
<input required="required" />
```
许多 HTML 属性是{{Glossary("Boolean/HTML", "布尔属性")}}。这些属性的值仅由属性的存在或不存在来控制。参见{{Glossary("Boolean/HTML", "布尔属性")}}以获取更多信息。

## 属性的反射

Expand All @@ -33,7 +25,7 @@ l10n:
<input placeholder="原始占位符" />
```

我们可以使用 {{domxref("HTMLInputElement.placeholder")}} 检查属性与 {{domxref("HTMLInputElement.placeholder")}} 之间的反射
我们可以使用以下代码检查 {{domxref("HTMLInputElement.placeholder")}} 与属性之间的反射

```js
const input = document.querySelector("input");
Expand All @@ -43,10 +35,18 @@ console.log(input.placeholder); // 与 `attr.value` 打印的值相同

// 更改占位符的值也会更改反射属性的值。
input.placeholder = "修改过的占位符";
console.log(attr.value); // 打印出 `修改过的占位符`
console.log(attr.value); // 打印 `修改过的占位符`
```

## 参见

- [HTML 属性参考](/zh-CN/docs/Web/HTML/Attributes)
- 关于 HTML 的[全局属性](/zh-CN/docs/Web/HTML/Global_attributes)的信息
- [W3C XML 推荐标准](https://www.w3.org/TR/xml#sec-starttags)中的 XML StartTag 属性推荐标准
- 相关术语:
- {{Glossary("Element", "元素")}}
- {{Glossary("Tag", "标签")}}
- {{Glossary("HTML")}}
- {{Glossary("XML")}}
- {{Glossary("Boolean/HTML", "布尔属性")}}
- {{Glossary("Enumerated", "枚举属性")}}