From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../zh-cn/web/api/htmlslotelement/name/index.html | 63 ++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 files/zh-cn/web/api/htmlslotelement/name/index.html (limited to 'files/zh-cn/web/api/htmlslotelement/name') diff --git a/files/zh-cn/web/api/htmlslotelement/name/index.html b/files/zh-cn/web/api/htmlslotelement/name/index.html new file mode 100644 index 0000000000..b00202e056 --- /dev/null +++ b/files/zh-cn/web/api/htmlslotelement/name/index.html @@ -0,0 +1,63 @@ +--- +title: HTMLSlotElement.name +slug: Web/API/HTMLSlotElement/name +tags: + - name + - 名称 + - 属性 + - 影子DOM + - 插槽 +translation_of: Web/API/HTMLSlotElement/name +--- +

{{APIRef("Shadow DOM API")}}

+ +

 元素{{domxref("HTMLSlotElement")}}的name属性, 可以获取和设置属性值. 插槽提供了web组件的摆放位置,辅助用户布局。

+ +

语法

+ +
var name = htmlSlotElement.name
+htmlSlotElement.name = name
+
+ +

+ +

一个 {{domxref('DOMString')}}.

+ +

例子

+ +

下面的片段来自 slotchange example (see it live also).

+ +
let slots = this.shadowRoot.querySelectorAll('slot');
+slots[1].addEventListener('slotchange', function(e) {
+  let nodes = slots[1].assignedNodes();
+  console.log('Element in Slot "' + slots[1].name + '" changed to "' + nodes[0].outerHTML + '".');
+});
+ +

这里我们获取所有插槽的引用, 然后给模板里的第二个插槽增加事件— 跟踪内容变化.

+ +

每当附加在插槽中的内容变化, 我们都记录插槽相关的内容.

+ +

规格

+ + + + + + + + + + + + + + +
规格状态注释
{{SpecName('HTML WHATWG','#dom-slot-name','name')}}{{Spec2('HTML WHATWG')}} 
+ +

浏览器兼容性

+ +
+ + +

{{Compat("api.HTMLSlotElement.name")}}

+
-- cgit v1.2.3-54-g00ecf