聚合物获取纸张输入值 [英] Polymer Get Paper Input Value

查看:71
本文介绍了聚合物获取纸张输入值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在短时间内使用聚合物,现在我想获得纸张输入的价值.我不知道该怎么办. 这不起作用:

this.form.password

我想获取此字段的值:

<paper-input label="Password" type="password" id="password" name="password" size="25" value=""></paper-input>

我还希望获得用于提交电子邮件输入的输入:

<paper-input label="Login" id="email" name="email" size="25" value=""></paper-input>

我正在使用以下提交方式

:

<paper-button raised value="Login" type="submit" onclick="formhash(this.form, this.form.password);">Login</paper-button>

使用正常的输入字段可以正常工作.

解决方案

您可以使用document.querySelector('#password').valueformhash()函数调用中或函数定义内使用ID为passwordpaper-input值. /p>

您还可以使用Polymer的自动查找节点使用其id获取元素的值.其中将表单/输入保留在custom-element中,并使用this.$.password.value来获取ID为password的元素的值.像这样

<!-- create a custom component my-form --> 
<dom-module id="my-form">
    <template> 
      <form is="iron-form" id="form" method="post">
        <paper-input name="name" label="name" id="name"></paper-input>
        <paper-button raised on-click="submitForm">Submit</paper-button>
      </form>
    </template>
    <script type="text/javascript">
        Polymer({
            is: "my-form",
            submitForm: function() {
                alert(this.$.name.value);
                if(this.$.name.value != "") // whatever input check
                   this.$.form.submit();
            }
        })
    </script>
</dom-module>

<my-form></my-form> <!-- use custom-component my-form -->

I am using Polymer for a short time and now i want to get the value of a paper input. I don't know how can I do this. This is not working:

this.form.password

I want to get the Value of this field:

<paper-input label="Password" type="password" id="password" name="password" size="25" value=""></paper-input>

I also want get the Input for submitting of the e-mail input:

<paper-input label="Login" id="email" name="email" size="25" value=""></paper-input>

For submitting I am using:

<paper-button raised value="Login" type="submit" onclick="formhash(this.form, this.form.password);">Login</paper-button>

With normal input fields is this working.

解决方案

You can use document.querySelector('#password').value to get the value of paper-input with id password in the formhash() function call or inside the function definition.

You can also use polymer's Automatic node finding to get value of an element using its id. In which keep the form/input in custom-element and use this.$.password.value to get the value of an element with id password. Like this

<!-- create a custom component my-form --> 
<dom-module id="my-form">
    <template> 
      <form is="iron-form" id="form" method="post">
        <paper-input name="name" label="name" id="name"></paper-input>
        <paper-button raised on-click="submitForm">Submit</paper-button>
      </form>
    </template>
    <script type="text/javascript">
        Polymer({
            is: "my-form",
            submitForm: function() {
                alert(this.$.name.value);
                if(this.$.name.value != "") // whatever input check
                   this.$.form.submit();
            }
        })
    </script>
</dom-module>

<my-form></my-form> <!-- use custom-component my-form -->

这篇关于聚合物获取纸张输入值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆