链接点击jQuery返回假 [英] Returning false on link click jquery
本文介绍了链接点击jQuery返回假的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望有一个链接,该链接在单击时会打开弹出窗口,但是如果用户未启用JS,我希望它能在新窗口中打开页面.
以下内容似乎无效,
<a id="tac-link" target="_blank" href="tac.html">terms and conditions</a>
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=550,height=600,left = 445,top = 150');");
}
$('tac-link').click(function() {
popUp('tac.html');
return false;
});
解决方案
为了使此功能与浏览器更加兼容,您需要将事件对象传递给click
处理程序,然后调用e.preventDefault();
.>
示例:
$( '#button' ).click( function( e ) {
//... your code...
e.preventDefault();
return false;
} );
I wish to have a link which opens popup when clicked however I wish it to open a page in a new window if the user doesn't have JS enabled.
The following doesn't seem to work,
<a id="tac-link" target="_blank" href="tac.html">terms and conditions</a>
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=550,height=600,left = 445,top = 150');");
}
$('tac-link').click(function() {
popUp('tac.html');
return false;
});
解决方案
In order to make this functionality more browser-compatible, you need to pass the event object to the click
handler, then call e.preventDefault();
.
example:
$( '#button' ).click( function( e ) {
//... your code...
e.preventDefault();
return false;
} );
这篇关于链接点击jQuery返回假的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文