对于那些启用了 javascript 的用户,点击它们应该执行 OnClick()
对于那些禁用了 javascript 的用户,点击它们应该只是转到某个地方.html,
假设只有 $('#link') 可以访问,怎么办?
For those with javascript enabled,click on them should do OnClick()
For those with javascript disabled,click on them should just go to somewhere.html,
Suppose only $('#link') is accessible,how to do that?
发布评论
评论(3)
像这样:
通过编写
return false
,链接将不会被跟随。如果禁用 Javascript,则不会添加点击处理程序,并且链接将正常运行。
Like this:
By writing
return false
, the link will not be followed.If Javascript is disabled, the click handler won't be added, and the link will behave normally.
$("#link").bind("click", function(e){alert("clicked"); e.preventDefault(); return false;});
这将警告“已单击”,然后取消默认操作。如果 JavaScript 被禁用,则链接将被跟随。
$("#link").bind("click", function(e){alert("clicked"); e.preventDefault(); return false;});
This will alert "clicked" and then cancel the default action. If Javascript is disabled, the link is followed.
使用
click
函数。将return false
添加到函数末尾以防止超链接后面的默认点击操作:Use the
click
function. Addreturn false
to the end of your function to prevent the default action of the click, which is following the hyperlink: