不,不在 Polymer 元素之外。
在阅读了 Polymer 之后,看起来您只能在 Polymer 元素内的脚本中访问 Polymer 元素的 shadow-DOM。关于自动节点查找的 Polymer 文档说:
在组件的 this.$ 哈希中自动引用组件的影子 DOM 中带有 id 属性的每个节点。
这意味着您可以将<script>
标签作为兄弟元素添加到<template>
您this.$.test
想要的元素的位置。
<polymer-element name="my-component">
<template>
<div id='test'>CONTENT</div>
</template>
<script>
Polymer('my-component', {
logNameValue: function () {
console.log('polymer element', this.$.test);
console.log('jQuery wrapper of polymer element', $(this.$.test));
}
});
</script>
</polymer-element>