$("a").on("click", function (e) {
doSomething();
});
...
<a href="http://website.com">My Link</a>
Run Code Online (Sandbox Code Playgroud)
将doSomething()在"HREF"前始终运行,在每个浏览器?
Cla*_*edi 21
是的,您的处理程序将始终首先运行.例如,这就是允许您在必要时取消默认行为(导航到href url)的原因
$("a").on("click", function (e) {
e.preventDefault(); // --> if this handle didn't run first, this wouldn't work
doSomething();
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17202 次 |
| 最近记录: |