event.preventDefault()方法可防止浏览器执行所选元素的默认操作。
例如:
阻止链接跟随URL
阻止提交按钮提交表单
使用event.isDefaultPrevented()方法检查事件是否调用了preventDefault()方法。
event.preventDefault()
阻止链接打开URL:
$("a").click(function(event){
event.preventDefault();
});测试看看‹/›阻止提交按钮提交表单:
$("#submit").click(function(event){
event.preventDefault();
});测试看看‹/›| 参数 | 描述 |
|---|---|
| event | 该事件的参数来自事件绑定功能 |