这是我的演示代码
<link rel="import" href="../bower_components/polymer/polymer.html">
<script type="text/javascript">
function myFunction() {
console.log('this workes');
}
</script>
<dom-module id="element-a">
<template>
<div style="text-align: center;">
<label for="fileinput" class="custom-file-upload">Change Picture</label>
<input id="fileinput" type="file" onchange="myFunction()"/>
</div>
</template>
<script>
Polymer({
is: 'element-a',
myPolymerFunction: function(){
console.log('success')
}
});
</script>
</dom-module>
在上面的代码中,当我选择新图片时,onchange
事件将被制作,并致电myFunction()
。如何以相同的方式调用聚合物功能?
当我用myPolymerFunction
替换onchange
时,它给出以下错误
Uncaught ReferenceError: myPolymerFunction is not defined at HTMLInputElement.onchange
-
绑定聚合物函数时不要使用"((。
-
" on Change"应该是"变更"
<dom-module id="my-element"> <template> <input id="fileinput" type="file" on-change="hello"/> </template> <script> class MyElement extends Polymer.Element { static get is() { return 'my-element'; } hello(evt) { console.log(evt); } } window.customElements.define(MyElement.is, MyElement); </script> </dom-module>
jsbin:http://jsbin.com/rixibucepa/edit?html,console,output