我要实现一个功能 双击添加一个图标 然后右键点击图片产生一个菜单 点击菜单相应的选项执行相应的动作。
但是现在我的代码右键菜单无法调用函数。求教,谢谢。
JS代码如下:dblClickHandler: function(e, toolbar){

        function cancleMenu() 
        { 
             alert("cancle menu");
   //mlay.style.display="none"; 
            //Event.stop(e);
        } 

var mname=new Array( 
        "Edit", 
        "Delete",
        "Cancle"
        ); 
      
        var murl=new Array( 
        "cancleMenu();",//无反映
        "cancleMenu()",//无反应
        "cancleMenu();"//无反应
        ); 
        
        var ph=18,mwidth=50;//每条选项的高度,菜单的总宽度 
        var bgc="#eee",txc="black";//菜单没有选中的背景色和文字色 
        var cbgc="darkblue",ctxc="white";//菜单选中的选项背景色和文字色         var mover="this.style.background='"+cbgc+"';this.style.color='"+ctxc+"';" 
        var mout="this.style.background='"+bgc+"';this.style.color='"+txc+"';"         this.div = Util.createDiv('div');
        this.mapDiv = toolbar.mapDiv;
        this.mapDiv.appendChild(this.div);                
        this.mouseDownPixel = Util.getMouseRelativePixel(e, this.mapDiv);
        this.lastX=this.mouseDownPixel.x-12;   
        this.lastY=this.mouseDownPixel.y-35;
        this.div.id = "er_"+i ;
        this.div.style.position = "absolute";
        this.div.style.left = this.lastX + "px";
        this.div.style.top = this.lastY + "px";
        var icon = document.createElement("img");
        icon.style.cursor = "pointer";
        icon.src = ImageBaseDir+'er_large.png';

        icon.onclick = function() {
   return false;
        };
        this.div.appendChild(icon);

        this.menuDiv=Util.createDiv('div');
        this.div.appendChild(this.menuDiv);    
        this.menuDiv.id = "mlay" ;
        this.menuDiv.style.position="absolute";
        this.menuDiv.style.cursor="default";
        this.menuDiv.onClick="return false;"

        this.div.oncontextmenu=function() 
        { 
   this.style.background=bgc; 
            this.style.color=txc; 
            this.style.width=mwidth; 
            this.style.height=mname.length*ph; 
            var h="<table width=100% height="+mname.length*ph+"px cellpadding=0 cellspacing=0 border=0>"; 
            var i=0; 
            for(i=0;i<mname.length;i++) 
            { 
                 h+="<tr align=center><td style='font-size:9pt;'><input id="+i+" height="+ph+" type='button' onclick=\""+murl[i]+"\" onMouseover=\""+mover+"\" onMouseout=\""+mout+"\" style='border:0px solid #999;width:100%' name="+i+" value="+mname[i]+" /> </td></tr>"; 
            } 
            h+="</table>"; 
            this.innerHTML=h; 

        }          function fresh() 
        { 
           
        } 
    },

解决方案 »

  1.   

    楼主没有给出html代码
    参考:
    http://www.cnblogs.com/luluping/archive/2009/04/20/1440031.html
    http://blog.csdn.net/qiume/archive/2010/06/22/5687674.aspx
      

  2.   

    var murl=new Array(  
      "cancleMenu();",//无反应
      "cancleMenu()",//无反应
      "cancleMenu();"//无反应
      ); 
    这里写成
    var murl=new Array(  
      "alert('delete');",//显示
      "alert('delete');,//显示
      "cancleMenu();"//不显示
      ); 
    就是无法调用函数。这是为什么啊?
      

  3.   


    var murl=new Array(  
      "alert('delete');",//显示
      "alert('delete');,//显示
      "cancleMenu();"//不显示
      );  
    for (var i = 0; i < murl.length; i++) {
          eval(murl[i]);
    }var murl=new Array(  
      "cancleMenu();",//无反应
      "cancleMenu()",//无反应
      "cancleMenu();"//无反应
      );
    和上面一样
      

  4.   

    var murl=new Array(  
      "alert('delete');",
      "alert('delete');,
      "cancleMenu();"
      );  for (var i = 0; i < murl.length; i++) {
          eval(murl[i]);
    }
    确实是这样,直接调用没有问题。但是为什么右键弹出菜单之后点击相应的选项却不行?