javascript 如何提交带有聚合物的表格?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24952217/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to submit a form with polymer?
提问by alexP
I've have this polymer contact-element:
我有这个聚合物接触元件:
<polymer-element name="contact-element">
<template>
<paper-input label="Your Name" id="contact-name" floatingLabel></paper-input>
<paper-input multiline label="Your text here..." id="contact-message" floatingLabel></paper-input>
<paper-button label="Send Data" id="contact-submit" raisedButton></paper-button>
</template>
<script>
Polymer({});
</script>
</polymer-element>
It's included in this index.html
它包含在这个 index.html 中
<form action="/sendMessage" method="GET">
<contact-element></contact-element>
</form>
Is there an submit-attribute for the paper-button or do I have to do the submit with JS?
纸按钮是否有提交属性,还是我必须用 JS 提交?
回答by Travis Reeder
Try the ajax-form element: http://ajax-form.raynicholus.com.
试试 ajax-form 元素:http: //ajax-form.raynicholus.com。
It supports the paper elements.
它支持纸元素。
回答by M H
For any future Readers, now that 1.0 is released:
对于任何未来的读者,现在 1.0 已发布:
This is basic html form processing. At the time of this writing, Polymer now has the iron-form, but you still submit it like any other form.
这是基本的 html 表单处理。在撰写本文时, Polymer 现在具有iron-form,但您仍然可以像提交任何其他表单一样提交它。
<form is="iron-form" id="form" method="post" action="/">
<paper-input name="testinput"></paper-input>
<paper-button raised click="document.getElementById('form').submit();">
Post
</paper-button>
</form>
回答by sesteva
From Polymer's blog: https://blog.polymer-project.org/featured/2014/09/23/featured-002/
来自 Polymer 的博客:https: //blog.polymer-project.org/featured/2014/09/23/featured-002/
Ray Nicholus' ajax-form element provides a simple way to submit forms. ajax-form works with traditional form elements, as well as any custom elements that have both a name attribute and a value – including the Core and Paper input elements.
Ray Nicholus 的 ajax-form 元素提供了一种提交表单的简单方法。ajax-form 适用于传统的表单元素,以及任何具有 name 属性和值的自定义元素——包括 Core 和 Paper 输入元素。
https://github.com/rnicholus/ajax-formhttp://ajax-form.raynicholus.com
https://github.com/rnicholus/ajax-form http://ajax-form.raynicholus.com
回答by CletusW
Since, as you pointed out, paper-button
s do not extend the native button
element, you will have to either write your ownJavaScript to handle form submission or wait for the upcomingpaper-forms
Polymer element.
正如您所指出的,paper-button
s 不扩展本机button
元素,因此您必须编写自己的JavaScript 来处理表单提交或等待即将到来的paper-forms
Polymer 元素。