Jquery 我想让我的网站有多个上下文菜单

Jquery 我想让我的网站有多个上下文菜单,jquery,html,popup,contextmenu,Jquery,Html,Popup,Contextmenu,嗨,我想我的网站有多个上下文菜单,每个都回答一个div内的右键点击。(不同的div不同的菜单)。问题是我找到的所有菜单都不允许我使用此html 5强制下载链接: <a href="Title Blue.png" download="Title Blue.png">Download Title Picture</a> <span id=”op”>Demo Time</span> // For showing output. <div id

嗨,我想我的网站有多个上下文菜单,每个都回答一个div内的右键点击。(不同的div不同的菜单)。问题是我找到的所有菜单都不允许我使用此html 5强制下载链接:

<a href="Title Blue.png" download="Title Blue.png">Download Title Picture</a>
<span id=”op”>Demo Time</span> // For showing output.
  <div id=’cntnr’>                         // Context menu container. 
    <ul id=’items’>                        // List of items in context menu.   
      <li>Item1</li>                      // Items to show in context menu. 
      <li>Item2</li>
      <li>Item3</li>
      <li>Item4</li>
      <li>Item5</li>
    </ul>
  </div>

我想这是我的上下文菜单上的一个项目的链接

我找到了这段脚本,但它不起作用,因为它的某个地方有语法错误

<script>
$(document).bind(“contextmenu”,(e)) {
   e.preventDefault();                 // To prevent the default context menu.
   $(“#cntnr”).css(“left”, e.pageX);   // For updating the menu position.
   $(“#cntnr”).css(“top”, e.pageY);    // 
   $(“#cntnr”).fadeIn(500, startFocusOut()); //  For bringing the context menu in picture.
};
function startFocusOut() {
    $(document).on(“click”, function () {   
        $(“#cntnr”).hide(500);              // To hide the context menu
        $(document).off(“click”);           
    });
}
$(“#items > li”).click(function () {
    $(“#op”).text(“You have selected “ + $(this).text());  // Performing the selected function.
});
</script>"

$(document.bind(“contextmenu”,(e)){
e、 preventDefault();//阻止默认上下文菜单。
$(“#cntnr”).css(“left”,e.pageX);//用于更新菜单位置。
$(“#cntnr”).css(“top”,e.pageY);//
$(“#cntnr”).fadeIn(500,startFocusOut());//用于在图片中显示上下文菜单。
};
函数startFocusOut(){
$(文档).on(“单击”,函数(){
$(“#cntnr”).hide(500);//隐藏关联菜单
$(文档)。关闭(“单击”);
});
}
$(“#items>li”)。单击(函数(){
$(“#op”).text(“您已选择”+$(this.text());//执行所选函数。
});
"
另一半只是标准html列表,与我的html 5下载链接兼容:

<a href="Title Blue.png" download="Title Blue.png">Download Title Picture</a>
<span id=”op”>Demo Time</span> // For showing output.
  <div id=’cntnr’>                         // Context menu container. 
    <ul id=’items’>                        // List of items in context menu.   
      <li>Item1</li>                      // Items to show in context menu. 
      <li>Item2</li>
      <li>Item3</li>
      <li>Item4</li>
      <li>Item5</li>
    </ul>
  </div>
演示时间//用于显示输出。 //上下文菜单容器。
    //上下文菜单中的项目列表。
  • Item1
  • //要在关联菜单中显示的项目。
  • 项目2
  • 项目3
  • 项目4
  • 项目5
有人能识别错误,或者告诉我在不同的上下文菜单中使用HTML5链接的错误吗


谢谢

首先,您需要使用
更改代码中的所有

HTML:

<a href="Title Blue.png" download="Title Blue.png">Download Title Picture</a>

<span id='op'>Demo Time</span> 
  <div id='cntnr'>                         
    <ul id='items'>                      
      <li>Item1</li>                     
      <li>Item2</li>
      <li>Item3</li>
      <li>Item4</li>
      <li>Item5</li>
    </ul>
  </div>
$(document).bind('contextmenu',function(e) {
   e.preventDefault();                 // To prevent the default context menu.
   $('#cntnr').css('left', e.pageX);   // For updating the menu position.
   $('#cntnr').css('top', e.pageY);    // 
   $('#cntnr').fadeIn(500, startFocusOut()); //  For bringing the context menu in picture.
});
function startFocusOut() {
    $(document).on('click', function () {   
        $('#cntnr').hide(500);              // To hide the context menu
        $(document).off('click');           
    });
}
$('#items > li').click(function () {
    $('#op').text('You have selected ' + $(this).text());  // Performing the selected function.
});

工作小提琴

任何控制台错误?请用firebug检查并查看错误。并将此引号更改为“像这样”"如何将这些片段组合到html文档中?我想我知道,但当我将这些片段组合到html文档中时,什么都没有发生。我还没有做什么?@user3304628将Js代码包装在
标记中,正如上面所示,不要忘了包含
jQuery
库。我想出来了,我可以用它制作多个菜单吗?这样我就可以应用它了它可以连接到多个div吗?