gpt4 book ai didi

javascript - 将标准右键单击选项添加到自定义右键单击

转载 作者:行者123 更新时间:2023-11-29 19:28:03 25 4
gpt4 key购买 nike

如果可能的话,我想添加标准选项,例如检查元素、查看源代码等以自定义右键单击。

这是我的 JavaScript...

<script type="text/javascript">
$(document).bind("contextmenu", function (event) {

// Avoid the real one
event.preventDefault();

// Show contextmenu
$(".custom-menu").finish().toggle(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 (e) {

// If the clicked element is not the menu
if (!$(e.target).parents(".custom-menu").length > 0) {

// Hide it
$(".custom-menu").hide(100);
}
});


// If the menu element is clicked
$(".custom-menu li").click(function(){

// This is the triggered action name
switch($(this).attr("data-action")) {

// A case for each action. Your actions here
case "first": alert("first"); break;
case "second": alert("second"); break;
case "third": alert("third"); break;
case "fourth": alert("fourth"); break;
case "fifth": alert("fifth"); break;
case "sixth": alert("sixth"); break;
case "seventh": alert("seventh"); break;
}

// Hide it AFTER the action was triggered
$(".custom-menu").hide(100);
});
</script>

这是我的 CSS...

.custom-menu {
display: none;
z-index: 1000;
position: absolute;
overflow: hidden;
border: 1px solid #CCC;
white-space: nowrap;
font-family: sans-serif;
background: #FFF;
color: #333;
border-radius: 5px;
padding: 0;
}

.custom-menu a {
text-decoration:none;
color:#333;
}


.custom-menu li {
padding: 8px 12px;
cursor: pointer;
list-style-type: none;
}

.custom-menu li:hover {
background-color: #DEF;
}

这是我的 HTML...

<ul class='custom-menu'>
<li data-action="first"><a href="/">Home</a></li>
<li data-action="second"><a href="/profile.php?id=<?php echo $memberID; ?>">Profile</a></li>
<li data-action="third"><a href="/friends.php">Friends</a></li>
<li data-action="fourth"><a href="/messages.php">Messages</a></li>
<li data-action="fifth"><a href="/settings.php">Settings</a></li>
<li data-action="sixth"><a href="/apps.php">Apps</a></li>
<li data-action="seventh"><a href="/logout.php">Logout</a></li>
</ul>

我目前使用的是有效的并且看起来不错。我宁愿保持原样。只需添加选项。我将不胜感激,非常感谢。

最佳答案

I would like to add standard options, such as inspect element, view source, etc. to custom right-click...

我们都不会。 :-) 恐怕不,这种集成目前*不可能。 (有些浏览器甚至不允许您拦截该事件。)


* 我说“当前”是因为最近新界面正在相当迅速地添加到浏览器中,所以也许最终......

关于javascript - 将标准右键单击选项添加到自定义右键单击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29798524/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com