为什么这不起作用?
<input type="file" id="kmlFiles2" multiple onchange="function(){alert('why does this not work')}()">
chrome 给我一个错误, 未捕获的语法错误:意外的标记 (。
Firefox 告诉我SyntaxError: function statement requires a name。
但这真的有用吗?
<input type="file" id="kmlFiles2" multiple onchange="alert('but this does work')">
我问是因为我正在尝试使用 MVC 框架将代码注入(inject) onchange 事件。
最佳答案
onchange="(function(){alert('this should work')})()"
关于javascript - html 输入 onchange 不接受匿名函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24069843/