javascript - html 输入 onchange 不接受匿名函数

标签 javascript html model-view-controller input

为什么这不起作用?

 <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')">

http://jsfiddle.net/ewzyV/

我问是因为我正在尝试使用 MVC 框架将代码注入(inject) onchange 事件。

最佳答案

onchange="(function(){alert('this should work')})()"

关于javascript - html 输入 onchange 不接受匿名函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24069843/

相关文章:

python - 在元素和属性中搜索字符串

javascript - 在 Angular gridOptions 中调用另一个函数

c# - 将 URL 重定向或重写为新的

javascript - 在 React js 中收到错误 "this.props.sumOfPrices is not a function"?

javascript - 检测 IE 的 Metro UI 版本

javascript - 鼠标悬停时突出显示整个系列

java - 如何将 REST channel 添加到 Spring Webflow 应用程序?

javascript - jQuery 返回的 DOM 元素的父级

html - 调整网页大小导致网站添加白底溢出

javascript - 如何将自动定时器设置为内容幻灯片?