这是我的演示代码
<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()
。如何以相同的方式调用聚合物功能?
当我用onchange
替换myPolymerFunction
时,会出现以下错误
Uncaught ReferenceError: myPolymerFunction is not defined at HTMLInputElement.onchange
答案 0 :(得分:2)
请勿使用&#34;()&#34;当结合聚合物功能时。
&#34;平变化&#34;应该是&#34;在变化&#34;
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "node",
"request": "launch",
"program": "c:/Users/yourUserName/AppData/Roaming/npm/node_modules/protractor/bin/protractor",
"args": [
"${workspaceRoot}/conf.js"
],
"stopOnEntry": false,
"cwd": "${workspaceRoot}",
"preLaunchTask": null,
"runtimeExecutable": null,
"runtimeArgs": [
"--nolazy"
],
"env": {
"NODE_ENV": "development"
},
"externalConsole": false,
"sourceMaps": false
},
{
"name": "Attach",
"type": "node",
"request": "attach",
"port": 5858,
"address": "localhost",
"restart": false,
"sourceMaps": false,
"localRoot": "${workspaceRoot}",
"remoteRoot": null
},
{
"name": "launch",
"type": "node",
"request": "launch",
"processId": "${command.PickProcess}",
"port": 5858,
"sourceMaps": false,
"outDir": null
}
]
}