Включить отключение пользовательского меню, вызываемого правой кнопкой мышиJquery

Программирование на jquery
Ответить
Anonymous
 Включить отключение пользовательского меню, вызываемого правой кнопкой мыши

Сообщение Anonymous »

http://jsfiddle.net/CmJ9z/
У меня есть флажок: если он установлен, мне нужно пользовательское меню, вызываемое правой кнопкой мыши, но если оно не имеет контекстного меню браузера по умолчанию. Однако, как только этот флажок снят, пользовательское меню все равно появляется, а при повторной установке оно отображается/скрывается/показывается.
Что я делаю не так?
if ( $("#tm").prop('checked') === true ) {
// Trigger action when the contexmenu is about to be shown
$(document).bind("contextmenu", function (event) {
// Avoid the real one
event.preventDefault();
$("#custom-menu").hide(100);
// Show contextmenu
if ($("#showcustom-menu").show() === true) {
$("#custom-menu").hide(100).
// In the right position (the mouse)
css({
top: event.pageY + "px",
left: event.pageX + "px"
});
} else {
$("#custom-menu").show(100).
// In the right position (the mouse)
css({
top: event.pageY + "px",
left: event.pageX + "px"
});
}
});

// If the document is clicked somewhere
$(document).bind("mousedown", function () {
$("#custom-menu").hide(100);
});

$("#custom-menu li").click(function(){
// This is the triggered action name
switch($(this).attr("data-action")) {
// A case for each action. Should personalize to your actions
case "duplicate": alert("duplicate called"); break;
case "remove": alert("remove called"); break;
case "deselect": alert("deselect called"); break;
}
});
} else {

}
$("#tm").on('change', function() {
if ( $(this).prop('checked') === true ) {
// Trigger action when the contexmenu is about to be shown
$(document).bind("contextmenu", function (event) {
// Avoid the real one
event.preventDefault();
$("#custom-menu").hide(100);
// Show contextmenu
if ($("#custom-menu").show() === true) {
$("#custom-menu").hide(100).
// In the right position (the mouse)
css({
top: event.pageY + "px",
left: event.pageX + "px"
});
} else {
$("#custom-menu").show(100).
// In the right position (the mouse)
css({
top: event.pageY + "px",
left: event.pageX + "px"
});
}
});

// If the document is clicked somewhere
$(document).bind("mousedown", function () {
$("#custom-menu").hide(100);
});

$("#custom-menu li").click(function(){
// This is the triggered action name
switch($(this).attr("data-action")) {
// A case for each action. Should personalize to your actions
case "duplicate": alert("duplicate called"); break;
case "remove": alert("remove called"); break;
case "deselect": alert("deselect called"); break;
}
});
} else {

}
});


Подробнее здесь: https://stackoverflow.com/questions/247 ... click-menu
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Jquery»