Skip to content

Commit 23b342a

Browse files
committed
docs(dom): add document.currentScript
1 parent f71489d commit 23b342a

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

docs/dom/document.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,20 @@ var editor = document.getElementById('editor');
327327
editor.contentDocument.designMode = 'on';
328328
```
329329

330+
### document.currentScript
331+
332+
`document.currentScript`属性只用在`<script>`元素的内嵌脚本或加载的外部脚本之中,返回当前脚本所在的那个 DOM 节点,即`<script>`元素的 DOM 节点。
333+
334+
```html
335+
<script id="foo">
336+
console.log(
337+
document.currentScript === document.getElementById('foo')
338+
); // true
339+
</script>
340+
```
341+
342+
上面代码中,`document.currentScript`就是`<script>`元素节点。
343+
330344
### document.implementation
331345

332346
`document.implementation`属性返回一个`DOMImplementation`对象。该对象有三个方法,主要用于创建独立于当前文档的新的 Document 对象。

docs/stdlib/date.md

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ dateObj.toLocaleDateString([locales[, options]])
337337
dateObj.toLocaleTimeString([locales[, options]])
338338
```
339339

340-
这两个参数中,`locales`是一个指定所用语言的字符串,`options`是一个配置对象。下面是`locales`的例子。
340+
这两个参数中,`locales`是一个指定所用语言的字符串,`options`是一个配置对象。下面是`locales`的例子,分别采用`en-US``zh-CN`语言设定
341341

342342
```javascript
343343
var d = new Date(2013, 0, 1);
@@ -352,13 +352,23 @@ d.toLocaleTimeString('en-US') // "12:00:00 AM"
352352
d.toLocaleTimeString('zh-CN') // "上午12:00:00"
353353
```
354354

355-
下面是`options`的例子。
355+
`options`配置对象有以下属性。
356+
357+
- `dateStyle`:可能的值为`full``long``medium``short`
358+
- `timeStyle`:可能的值为`full``long``medium``short`
359+
- `month`:可能的值为`numeric``2-digit``long``short``narrow`
360+
- `year`:可能的值为`numeric``2-digit`
361+
- `weekday`:可能的值为`long``short``narrow`
362+
- `day``hour``minute``second`:可能的值为`numeric``2-digit`
363+
- `timeZone`:可能的值为 IANA 的时区数据库。
364+
- `timeZooneName`:可能的值为`long``short`
365+
- `hour12`:24小时周期还是12小时周期,可能的值为`true``false`
366+
367+
下面是用法实例。
356368

357369
```javascript
358370
var d = new Date(2013, 0, 1);
359371

360-
// 时间格式
361-
// 下面的设置是,星期和月份为完整文字,年份和日期为数字
362372
d.toLocaleDateString('en-US', {
363373
weekday: 'long',
364374
year: 'numeric',
@@ -367,7 +377,13 @@ d.toLocaleDateString('en-US', {
367377
})
368378
// "Tuesday, January 1, 2013"
369379

370-
// 指定时区
380+
d.toLocaleDateString('en-US', {
381+
day: "2-digit",
382+
month: "long",
383+
year: "2-digit"
384+
});
385+
// "January 01, 13"
386+
371387
d.toLocaleTimeString('en-US', {
372388
timeZone: 'UTC',
373389
timeZoneName: 'short'
@@ -380,7 +396,6 @@ d.toLocaleTimeString('en-US', {
380396
})
381397
// "12:00:00 AM China Standard Time"
382398

383-
// 小时周期为12还是24
384399
d.toLocaleTimeString('en-US', {
385400
hour12: false
386401
})

0 commit comments

Comments
 (0)