jQuery-UIダイアログボックスをポップアップとして表示したいユーザーがマウスの左ボタンまたは中央のボタンをクリックしたとき。左クリックでは機能しますが(アラートボックスが表示され、その後ポップアップが表示されます)、中央では機能しません(アラートボックスもポップアップも表示されません)。何が欠けていますか?
$("a.external").live("click", function(e){
if( e.which <= 2 ) {
e.preventDefault();
alert ("inside if");
}
popUp.start(this);
});
回答:
回答№1の17つかいます mousedown
または mouseup
の代わりに click
。そして(あなたが使用している場合を除いて 非常に 古いバージョンのjQuery)を使用する .on()
の代わりに .live()
:
$(document).on("mousedown", "a.external", function(e) {
if( e.which <= 2 ) {
e.preventDefault();
alert ("inside if");
}
popUp.start(this);
});
...理想的には、リンクよりもはるかに近い親要素を使用します document
.
デモ: http://jsfiddle.net/7S2SQ/
回答№2の場合は3
これをFirefox(40.0.3)で完全に機能させるには、実装する必要がありました .on("mouseup", fn)
、 次のように:
$(selector).on("mouseup", function (e) {
switch (e.which)
{
// Left Click.
case 1:
// By way of example, I"ve added Ctrl+Click Modifiers.
if (e.ctrlKey) {
// Ctrl+LeftClick behaviour.
} else {
// Standard LeftClick behaviour.
}
break;
// Middle click.
case 2:
// Interrupts "Firefox Open New Tab" behaviour.
break;
// Default behaviour for right click.
case 3:
return;
}
// Pass control back to default handler.
return true;
});