jQuery中的事件对象是什么?
回调函数采用单个参数;调用处理程序时,JavaScript事件对象将通过它传递。
事件对象通常是不必要的,并且会省略参数,因为当绑定处理程序时,通常会提供足够的上下文,以便确切地知道触发处理程序时需要执行的操作,但是有些属性需要访问。
让我们看一个isDefaultPrevented()方法的例子。该isDefaultPrevented()方法检查是否曾经在此事件对象上调用过event.preventDefault()。
示例
您可以尝试运行以下代码来学习如何在jQuery中使用偶数对象:
<html>
<head>
<title>jQuery isDefaultPrevented() method</title>
<script src = "https://cdn.staticfile.org/jquery/2.1.3/jquery.min.js"></script>
<script>
$(document).ready(function() {
$("a").click(function(event){
if ( event.isDefaultPrevented() ){
alert( "Default behavior is disabled - 1" );
}else{
alert( "Default behavior is enabled - 1" );
}
event.preventDefault();
if ( event.isDefaultPrevented() ){
alert( "Default behavior is disabled - 2" );
}else{
alert( "Default behavior is enabled - 2" );
}
});
});
</script>
</head>
<body>
<span>Click the following link and it won't work:</span>
<a href = "https://www.google.com">GOOGLE Inc.</a>
</body>
</html>热门推荐
10 八一幼儿祝福语大全简短
11 公司乔迁食堂祝福语简短
12 婚礼结束聚餐祝福语简短
13 儿媳买车妈妈祝福语简短
14 毕业送礼老师祝福语简短
15 同事辞职正常祝福语简短
16 恭贺新婚文案祝福语简短
17 金店立秋祝福语简短英文
18 婆婆高寿祝福语大全简短