<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>
这目前给出了一个错误:
Uncaught HierarchyRequestError: Failed to execute 'appendChild' on 'Node': Only one element on document allowed.
但是,如果我将 id 从“offices-list”更改为“officesList”,它就会起作用。我怎样才能做同样的事情来保持 ID 不变,即使用破折号?
最佳答案
这是 Polymer 的未决问题/增强:
https://github.com/Polymer/polymer/issues/1747还有https://github.com/Polymer/polymer/issues/150
解决方法是使用 this.$['offices-list']
关于javascript - 如果 id 有破折号,如何访问本地 DOM 中的元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31397470/