我正在使用Polymer来创建基于铁形式模板的表单:https://github.com/PolymerElements/iron-form/blob/master/demo/index.html使用formGet表单。我的代码是:
<form is="iron-form" id="formGet" method="get" action="/"
<paper-input name="name" label="* Name" required></paper-input>
<paper-input name="description" label="Description"></paper-input>
<paper-button raised onclick="submitHandler(event)">Submit</paper-button>
<paper-button raised onclick="resetHandler(event)">Reset</paper-button>
</form>
<script>
document.getElementById('formGet').addEventListener('iron-form-submit', display);
function display(event) {
var output = document.getElementById('output');
output.innerHTML = JSON.stringify(event.detail);
}
function submitHandler(event) {
Polymer.dom(event).localTarget.parentElement.submit();
}
function resetHandler(event) {
Polymer.dom(event).localTarget.parentElement.reset();
}
</script>
当我点击提交时,我收到错误: 无法读取null的“addEventListener”属性
答案 0 :(得分:0)
在脚本中尝试使用
包装代码HTMLImports.whenReady(function(){...});