Javascript 如果id有破折号,如何访问本地DOM中的元素? 聚合物({ 是:“姓名标签”, 就绪:函数(){ var div_new=document.createElement('div'); Polymer.dom(this.$.officelist).appendChild(div_new); } });
这当前给出了一个错误: 未捕获的HierarchyRequestError:无法在上执行“appendChild” “节点”:文档上只允许一个元素Javascript 如果id有破折号,如何访问本地DOM中的元素? 聚合物({ 是:“姓名标签”, 就绪:函数(){ var div_new=document.createElement('div'); Polymer.dom(this.$.officelist).appendChild(div_new); } });,javascript,polymer,Javascript,Polymer,这当前给出了一个错误: 未捕获的HierarchyRequestError:无法在上执行“appendChild” “节点”:文档上只允许一个元素 不过,如果我将id从“offices list”更改为“officesList”,它就可以工作了。如何保持id不变(即使用dash?这是Polymer的一个开放问题/增强功能: 也 解决方法是使用这个。$['offices-list']为什么您的id没有quotes@AbdulAhmad已编辑。谢谢您使用的是哪种版本的聚合物? <dom-mod
不过,如果我将id从“offices list”更改为“officesList”,它就可以工作了。如何保持id不变(即使用dash?这是Polymer的一个开放问题/增强功能: 也
解决方法是使用
这个。$['offices-list']
为什么您的id没有quotes@AbdulAhmad已编辑。谢谢您使用的是哪种版本的聚合物?
<dom-module id="name-tag">
<template>
<div id="offices-list"></div>
</template>
<script>
Polymer({
is: "name-tag",
ready: function() {
var div_new = document.createElement('div');
Polymer.dom(this.$.officesList).appendChild(div_new);
}
});
</script>
</dom-module>