找一个右键菜单先,用鼠标判断所在的对象是不是image1,是的话就弹出菜单.

解决方案 »

  1.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <TITLE> New Document </TITLE>
    <SCRIPT LANGUAGE="JavaScript">
    //show(x-location, y-location, width, height[, reference-element]);
    var oPopup = window.createPopup();//初始化窗体
    function initPopupWin(){
    oPopupBody = oPopup.document.body;
    oPopupBody.innerHTML = popupMenu.innerHTML;
    oPopupBody.style.textAlign = "center";
    oPopupBody.style.backgroundColor = "#ffff66";
    oPopupBody.style.border = "1 solid green";
    oPopupBody.style.fontSize = "9pt";
    oPopupBody.style.fontFamily = "Courier New";
    }//显示窗体
    function showPopupWin(referenceObj){
    initPopupWin();
    var xPos = event.offsetX+10;
    var yPos = event.offsetY+0;
    var width = 50;
    var height = 105;
    oPopup.show(xPos,yPos,width,height,referenceObj);
    }function test(obj,id,rowId){
    currentRow.value = rowId;
    showPopupWin(obj);
    }function deleteRow_f(rowId,delTable){
    delTable.deleteRow(rowId);
    }function saveRow_f(rowId,saveTable){
    var objTR = saveTable.firstChild.childNodes[rowId];
    var children = objTR.childNodes.length;
    var result;
    for(i=0;i<children-1;i++){
    result = objTR.childNodes[i].firstChild.value;
    if(typeof(result)=="undefined"){
    return;
    }
    result = " "+result+" ";
    if(result==""){
    result = " ";
    }
    objTR.childNodes[i].innerText=result;
    }
    }function modify_f(rowId,modiTable){
    var objTR = modiTable.firstChild.childNodes[rowId];
    var children = objTR.childNodes.length;
    var text;
    for(i=0;i<children-1;i++){
    text=objTR.childNodes[i].innerText;
    objTR.childNodes[i].innerHTML = "<input type='text' style='height:17px;width:100%' value="+text+">";
    }
    objTR.childNodes[i].innerHTML = "<img src='list.gif' border='0' value='1' onContextmenu='test(this,this.value,this.parentNode.parentNode.sectionRowIndex);return false;' alt='单击右键'>";
    }function insertRow_f(rowId,insertTable){
    var newRow = insertTable.insertRow(rowId);
    var col = newRow.insertCell(0); col.innerHTML = "<input type='text' style='height:17px;width:100%'>";
    col = newRow.insertCell(1);
    col.innerHTML = "<input type='text' style='height:17px;width:100%'>";
    col = newRow.insertCell(2);
    col.innerHTML = "<input type='text' style='height:17px;width:100%'>";
    col = newRow.insertCell(3);
    col.innerHTML = "<input type='text' style='height:17px;width:100%'>";
    col = newRow.insertCell(4);
    col.innerHTML = "<img src='list.gif' border='0' value='1' onContextmenu='test(this,this.value,this.parentNode.parentNode.sectionRowIndex);return false;' alt='单击右键'>";
    }</SCRIPT>
    </HEAD><BODY>
    <TABLE border="1" align="center" borderColorLight="pink" width="50%" id=listTable name=listTable cols=5 style="font-size: 9pt;text-align:center">
    <TR borderColorLight="yellowgreen" bgcolor="gainsboro" style="font-size: 11pt;">
    <TD>商品代码</TD>
    <TD>商品名称</TD>
    <TD>计价单位</TD>
    <TD>库存数量</TD>
    <TD>操作</TD>
    </TR>
    <TR>
    <TD>GOODS000000000000001</TD>
    <TD>保10洁</TD>
    <TD>辆</TD>
    <TD>1</TD>
    <TD><img src="list.gif" border="0" value="1" onContextmenu="test(this,this.value,this.parentNode.parentNode.sectionRowIndex);return false;" alt="单击右键"></TD>
    </TR>
    <TR>
    <TD>GOODS000000000000002</TD>
    <TD>小猪猪</TD>
    <TD>只</TD>
    <TD>only you</TD>
    <TD><img src="list.gif" border="0" value="2" onContextMenu="test(this,this.value,this.parentNode.parentNode.sectionRowIndex);return false;" alt="单击右键"></TD>
    </TR>
    <TR>
    <TD>GOODS000000000000003</TD>
    <TD>千年人参</TD>
    <TD>棵</TD>
    <TD>10</TD>
    <TD><img src="list.gif" border="0" value="1" onContextmenu="test(this,this.value,this.parentNode.parentNode.sectionRowIndex);return false;" alt="单击右键"></TD>
    </TR>
    <TR>
    <TD>GOODS000000000000004</TD>
    <TD>脑白金</TD>
    <TD>盒</TD>
    <TD>50</TD>
    <TD><img src="list.gif" border="0" value="1" onContextmenu="test(this,this.value,this.parentNode.parentNode.sectionRowIndex);return false;" alt="单击右键"></TD>
    </TR>
    <TR>
    <TD>GOODS000000000000005</TD>
    <TD>白吃</TD>
    <TD>个</TD>
    <TD>31</TD>
    <TD><img src="list.gif" border="0" value="1" onContextmenu="test(this,this.value,this.parentNode.parentNode.sectionRowIndex);return false;" alt="单击右键"></TD>
    </TR>
    <TR>
    <TD>GOODS000000000000006</TD>
    <TD>第十一本书</TD>
    <TD>本</TD>
    <TD>01</TD>
    <TD><img src="list.gif" border="0" value="1" onContextmenu="test(this,this.value,this.parentNode.parentNode.sectionRowIndex);return false;" alt="单击右键"></TD>
    </TR>
    </TABLE><DIV id=popupMenu style="display:none">
    <input type="hidden" id="currentRow">
    <TABLE border=1 bordercolor="white" bgcolor="wheat" borderColorLight="yellowgreen" style="font-size: 9pt;" width="100%" height="100%">
    <TR align="center">
    <TD>
    <DIV STYLE="cursor:hand" onmouseover="this.style.background='seashell'" onmouseout="this.style.background='wheat'" onclick="parent.insertRow_f(parent.listTable.rows.length,parent.listTable);parent.oPopup.hide();">添加</DIV>
    </TD>
    </TR>
    <TR align="center">
    <TD>
    <DIV STYLE="cursor:hand" onmouseover="this.style.background='seashell'" onmouseout="this.style.background='wheat'" onclick="parent.saveRow_f(currentRow.value,parent.listTable);parent.oPopup.hide();">保存</DIV>
    </TD>
    </TR>
    <TR align="center">
    <TD>
    <DIV STYLE="cursor:hand" onmouseover="this.style.background='seashell'" onmouseout="this.style.background='wheat'" onclick="parent.deleteRow_f(currentRow.value,parent.listTable);parent.oPopup.hide();">删除</DIV>
    </TD>
    </TR>
    <TR align="center">
    <TD>
    <DIV STYLE="cursor:hand" onmouseover="this.style.background='seashell'" onmouseout="this.style.background='wheat'" onclick="parent.modify_f(currentRow.value,parent.listTable);parent.oPopup.hide();">修改</DIV>
    </TD>
    </TR>
    <TR align="center">
    <TD>
    <DIV STYLE="cursor:hand" onmouseover="this.style.background='seashell'" onmouseout="this.style.background='wheat'" onclick="parent.insertRow_f(currentRow.value,parent.listTable);parent.oPopup.hide();">插入</DIV>
    </TD>
    </TR>
    </TABLE>
    </DIV>
    </BODY>
    </HTML>
      

  2.   

    javaEidolon您的方法不行的。我尝试过了。
      

  3.   

    自己先做一个,然后return false屏蔽掉
      

  4.   

    <img border=0 src=http://expert.csdn.net/images/csdn.gif 
     oncontextmenu="cc(this); return false"> <div id=pop style="position:absolute;width:100;height:50;z-index:99;display:none">
    <table border=0 bgcolor=#FF0000><tr><td align=center>图层菜单</td></tr></table></div><script language="JavaScript"><!--
    function cc(tt)
    {
      var daps  = document.all.pop.style;
      var ttop  = tt.offsetTop;     //TT控件的定位点高
      var thei  = tt.clientHeight;  //TT控件本身的高
      var tleft = tt.offsetLeft;    //TT控件的定位点宽
      var ttyp  = tt.type;          //TT控件的类型
      while (tt = tt.offsetParent){ttop+=tt.offsetTop; tleft+=tt.offsetLeft;}
      daps.top  = (ttyp=="image")? ttop+thei : ttop+thei+6; //层的 Y 坐标
      daps.left = tleft + 1;  //层的 X 坐标
      daps.display = "";  //层显示
    }
    function document.onclick()
    {
        document.all.pop.style.display=event.srcElement.tagName=="img"?'':'none'
    }
    //--></script>
      

  5.   

    ><img src="list.gif" border="0" value="1" onContextmenu="test(this,this.value,this.parentNode.parentNode.sectionRowIndex);return false;" alt="单击右键">
    注意这里有一个return false;的。