2011-03-22 72 views
0

好吧..所以我正在做一些网格工作,我有几个功能正在使用。 除了当我点击一个上下文菜单时它没有触发警报,一切正常。 仔细查看文档。 A “#Selector” 应该在这里,而不是文件使用...jQuery的上下文菜单等

// Show menu when #myDiv is clicked 
      jQuery(document).contextMenu({ 
       menu: 'myMenu' 
      }, 
       function(action, el, pos){  
         alert('Action: ' + action + '\n\n'); 
      }); 

当我改变

  jQuery(document).contextMenu({ 

// Show menu when #myDiv is clicked 
      jQuery("#grid").contextMenu({ 

这将激活所选上下文alert..But现在当我生成可拖动的容器时

jQuery("#grid").append("<div id='container"+container+"' class='container' style='border: 2px solid black;width:100px;height:100px;position: absolute !important;left:100px;top:"+Math.floor(Math.random()*601)+"px'><p style='background-color:lightblue;margin:0px'>------<span style='background-color:white'>"+container+"</span>------</p><br/>a</div>"); 
jQuery('#debug_container').html('Container Added'); 
jQuery('.container').draggable({handle: 'p',grid: [ 8,8 ], 
          containment: "#grid", 
          drag: function() { 
            var currentID = jQuery(this).attr('id').substr(9, 1);   
            setContainer(currentID);        
           }     
          });  

它不会让它进入... 原来将允许下降,但不会提醒。 我想都..

一如既往,任何帮助非常感谢。

回答

1

一些更多的调试,我发现我的问题的根源后,从jquery.contextMenu.js来到线37

jQuery(this).mousedown(function(e) { 
      var evt = e; 
      evt.stopPropagation(); 
      jQuery(this).mouseup(function(e) { 

//这样做固定我的问题==> // e.stopPropagation();

var srcElement = jQuery(this); 
       jQuery(this).unbind('mouseup'); 
       if(evt.button == 2) { 
        // Hide context menus that may be showing 
        jQuery(".contextMenu").hide(); 
        // Get this context menu 
        var menu = jQuery('#' + o.menu);