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 the translation of Location hash property #24798

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 2 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
27 changes: 13 additions & 14 deletions files/zh-cn/web/api/location/hash/index.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
---
title: "Location: hash"
title: Locationhash 属性
slug: Web/API/Location/hash
l10n:
sourceCommit: a2847ff3788f224ffb4cdf05cb0139e07fde7533
---

{{ APIRef("Location") }}

{{domxref("Location")}} 接口的 **`hash`** 属性返回一个 {{domxref("USVString")}},其中会包含 URL 标识中的 `'#'` 和 后面 URL 片段标识符
{{domxref("Location")}} 接口的 **`hash`** 属性返回一个字符串,其中包含一个 `'#'`,后跟 URL 的片段标识符——URL 试图指向的页面上的 ID

这里 fragment 不会经过[百分比编码](/zh-CN/docs/Glossary/percent-encoding)(URL 编码)。如果 URL 中没有 fragment,该属性会包含一个空字符串,`""`
该片段标识符没有进行{{Glossary("Percent-encoding", "百分号编码")}}。如果 URL 没有片段标识符,则此属性的值为空字符串 `""`

## Syntax
##

```plain
string = object.hash;
object.hash = string;
```
字符串。

## Examples
## 示例

```html
<a id="myAnchor" href="/zh-CN/docs/Location.href#Examples">Examples</a>
<a id="myAnchor" href="/zh-CN/docs/Location.href#示例">示例</a>
<script>
var anchor = document.getElementById("myAnchor");
console.log(anchor.hash); // 返回'#Examples'
const anchor = document.getElementById("myAnchor");
console.log(anchor.hash); // '#示例'
T34-active marked this conversation as resolved.
Show resolved Hide resolved
</script>
Copy link
Member

@yin1999 yin1999 Nov 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the example here appropriate?

The Location interface is accessible via Document.location and Window.location respectively.
--- from The Location interface

I don't think we should use an <a> element here, as <a> element is the implemetation of HTMLAnchorElement interface (not the Location interface).


Another issue on the content of this example. The hash property would be percent-encoded (see the test I made below), so the description above is also wrong 😢

It seems that only non-ascii characters will be encoded (details: mdn/content#37003)

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我先去修改上游

```

## Specifications
## 规范

{{Specifications}}

## Browser compatibility
## 浏览器兼容性

{{Compat}}