我按类名为一堆锚点分配了一个click事件,它适用于除Firefox之外的所有浏览器,这里是JS:
var click_addthis = function(e, href) {
if (!e) {
var e = window.event;
}
e.cancelBubble = true;
if (e.stopPropagation) e.stopPropagation();
window.open(href, "Share It", null);
return false;
}
$(document).ready(function() {
$(".addthis_button_facebook").click(function() { click_addthis(event, this.href) });
$(".addthis_button_twitter").click(function() { click_addthis(event, this.href) });
});
Run Code Online (Sandbox Code Playgroud)
我错过了什么吗?谢谢
Firefox的问题在于此部分:
$(document).ready(function() {
$(".addthis_button_facebook").click(function() { click_addthis(event, this.href) });
$(".addthis_button_twitter").click(function() { click_addthis(event, this.href) });
});
Run Code Online (Sandbox Code Playgroud)
您需要从处理程序传递事件,以使其一致,如下所示:
$(document).ready(function() {
$(".addthis_button_facebook").click(function(e) { click_addthis(e, this.href) });
$(".addthis_button_twitter").click(function(e) { click_addthis(e, this.href) });
});
Run Code Online (Sandbox Code Playgroud)
你也可以缩短它,因为你使用相同的功能(也return false停止传播):
$(document).ready(function() {
$(".addthis_button_facebook, .addthis_button_twitter").click(function() {
window.open(this.href, "Share It", null);
return false;
});
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6322 次 |
| 最近记录: |