如何访问Polymer元素上脚本部分的内部元素?
答案 0 :(得分:1)
以下是示例plnkr.co
<script>
Polymer("my-element", {
ready: function() {
//access the input element by 'Change' event
container_test = this.$.container; //correct one
// or: var container_test = this.shadowRoot.querySelector('#' + container);
// from: http://stackoverflow.com/questions/24588708/polymer-automatic-node-finding-with-dynamic-id-value
container_test.addEventListener('input', function(event) {
console.log('input event');
console.log(event);
console.log(event.target.tagName);
//console.log(event.target);
console.log(event.target.attributes.custom_attr.value);
});
},
//access the input element by Declarative event mapping
clickHandler: function(event) {
console.log('clickHandler event');
console.log(event);
console.log(event.target.tagName);
},
});
</script>