聚合物获取纸张输入值 [英] Polymer Get Paper Input Value
问题描述
我在短时间内使用聚合物,现在我想获得纸张输入的价值.我不知道该怎么办. 这不起作用:
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').value
在formhash()
函数调用中或函数定义内使用ID为password
的paper-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屋!