Javascript 在输入标记中的onchange事件上调用聚合函数
这是我的演示代码Javascript 在输入标记中的onchange事件上调用聚合函数,javascript,polymer-1.0,onchange,Javascript,Polymer 1.0,Onchange,这是我的演示代码 <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"> <temp
<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>
函数myFunction(){
console.log('this workes');
}
改变形象
聚合物({
是:'element-a',
myPolymerFunction:function(){
console.log('success')
}
});
在上面的代码中,每当我选择一个新图片时,onchange
事件将被触发,它将调用myFunction()
。如何用同样的方法调用聚合物函数
当我将onchange
替换为myPolymerFunction
时,会出现以下错误
Uncaught ReferenceError:myPolymerFunction未在HTMLInputElement.onchange中定义
绑定聚合物功能时不要使用“()”
“onchange”应为“on change”
类MyElement扩展了Polymer.Element{
静态get是(){return'my element';}
你好(evt){
控制台日志(evt);
}
}
window.customElements.define(MyElement.is,MyElement);
JSBin:
<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>