给出以下
HTML:
@H_301_2@<form>
<input type="number" required>
</form>
以下JavaScript工作正常:
@H_301_2@(function( jQuery ) { jQuery("input").bind("invalid",function(event) { console.log(event.type); }); })( jQuery );但是这个JavaScript代码没有:
@H_301_2@(function( jQuery ) { jQuery("form").on("invalid","input",function(event) { console.log(event.type); }); })( jQuery );任何人都知道为什么?
编辑:更新小提琴来纠正一个:http://jsfiddle.net/PEpRM/1
解决方法
无效事件不会起泡,它在
documentation中这样说,所以委托的事件处理程序将不会起作用,因为事件不会起泡.
这应该工作
@H_301_2@jQuery("form input").on("invalid",function(event) { console.log(event.type); });