jQuery on vs bind为无效事件类型

前端之家收集整理的这篇文章主要介绍了jQuery on vs bind为无效事件类型前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
给出以下 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); });

猜你在找的jQuery相关文章