javascript - polymer 从纸张输入元素中获取值

标签 javascript polymer

我刚刚开始探索 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.

DEMO

关于javascript - polymer 从纸张输入元素中获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49819817/

相关文章:

javascript - 更新 AngularJS 服务中的 radio 值

javascript - HTML 发布复选框中选定的值

JavaScript 代码到类图

javascript - 如何隐藏 goldenLayout 的特定标签页眉

javascript - polymer 核心标签和核心复选框动态

css - 如何动态导入样式表 Polymer 2.0

javascript - slideToggle() 问题

javascript - 如何在 Javascript 中使用 ComputedStyle 获取边框宽度?

javascript - 单击后突出显示表行?

javascript - 当输入类型 = 文件框已填充时更改按钮文本