【发布时间】:2017-11-21 18:06:56
【问题描述】:
我正在学习 Web 组件。要获取模板,我需要这样做:
<template>
<div>The sky is blue</div>
</template>
<script>
var tmpl = (document.currentScript||document._currentScript).ownerDocument.querySelector('template');
代替:
var tmpl = document.querySelector('template');
这部分我完全看不懂:(document.currentScript||document._currentScript).ownerDocument
currentScript 是什么,ownerDocument 是什么?什么目的?为什么它有效。请注意,我上面显示的模板代码是通过 link 元素拉入的。
【问题讨论】:
标签: javascript html dom web-component html5-template