我刚刚开始探索 polymer.js。我想从纸张输入元素中获取名称。它不起作用,警报为空。
<dom-module id="hello-world">
<template>
<h1> Hello [[name]]</h1>
<paper-input value="{{name}}"></paper-input>
<button onClick="{{getData}}">Get data</button>
</template>
<script>
Polymer({
is: "hello-world",
properties: {
name: {
type: String,
value: '1'
}
},
getData: function () {
alert(this.name);
}
})
</script>
最佳答案
如果您需要 onClick
事件,请在 polymer 模板中使用 on-click="getData"
。
....To add event listeners to local DOM children, use on-event annotations in your template. This often eliminates the need to give an element an id solely for the purpose of binding an event listener.
Because the event name is specified using an HTML attribute, the event name is always converted to lowercase. This is because HTML attribute names are case insensitive. So specifying on-myEvent adds a listener for myevent. The event handler name (for example, handleClick) is case sensitive. To avoid confusion, always use lowercase event names.
关于javascript - polymer 从纸张输入元素中获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49819817/