jib*_*ees 5 javascript jquery javascript-events
我只想在元素(a或div)上启用/禁用onclick和href.
我不知道该怎么做.
我可以通过在click事件上添加处理程序来禁用onclick,但href仍然可用.
$(this).unbind().click(function(event){
event.preventDefault();
return;
});
Run Code Online (Sandbox Code Playgroud)
编辑找到了一个元素
if ($(this).attr("href")) {
$(this).attr("x-href", $(this).attr("href"));
$(this).removeAttr("href");
}
Run Code Online (Sandbox Code Playgroud)
如果您返回falseonclick事件,href则会被忽略.
这将去Goole: <a
href="http://www.google.com"
onclick="alert('Go to
Google')">Test</a>
这不会发给谷歌: <a href="http://www.google.com" onclick="alert('Go to Google'); return false;">Test</a>
| 归档时间: |
|
| 查看次数: |
23759 次 |
| 最近记录: |