<script language="javascript">
var oPopup=null; //弹出菜单
var popWidth=110; //弹出菜单的宽度
var popHeight=140; //弹出菜单的高度
var curRow=null; //记录弹出菜单最后指向的行
function init(){
oPopup = window.createPopup();
var oPopBody = oPopup.document.body;
//设置菜单样式
oPopBody.style.backgroundColor = "scrollbar";
oPopBody.style.border = "2px solid";
oPopBody.style.borderColor = "buttonhighlight buttonshadow buttonshadow buttonhighlight"
var strHTML=""
strHTML+='<table oncontextmenu="return false;" onselectstart="return false;" id="tbMenu" ';
strHTML+=' style="cursor:default; width:100%; height:100%;font-size:12px;" border=0 cellpadding=0 cellspacing=2>';
//在这里扩展菜单的选项start
strHTML+='<tr operation="edit"><td> 编辑</td></tr>';
strHTML+='<tr operation="refresh"><td> 刷新</td></tr>';
strHTML+='<tr operation="addrowup"><td> 添加新行(上)</td></tr>';
strHTML+='<tr operation="addrowdown"><td> 添加新行(下)</td></tr>';
strHTML+='<tr operation="delrow"><td> 删除该行</td></tr>';
strHTML+='<tr operation="moveup"><td> 向上移动一行</td></tr>';
strHTML+='<tr operation="movedown"><td> 向下移动一行</td></tr>';
//在这里扩展菜单的选项end
strHTML+='</table>';
oPopBody.innerHTML=strHTML;
var tb = oPopup.document.getElementById("tbMenu");
var rs=tb.rows;
for(var i=0;i<rs.length;i++){
var row=rs[i];
addEvent(row);
}
}
function showMenu(){
var e=window.event;
var src=e.srcElement;
oPopup.show(window.event.clientX, window.event.clientY, popWidth, popHeight, document.body);
window.event.returnValue=false;
}
function addEvent(row){
row.attachEvent("onmouseover",function(){selRow(row)});
row.attachEvent("onclick",function(){onEvent(row)});
}
function selRow(src){
if(curRow!=null){ curRow.style.backgroundColor="scrollbar"; curRow.style.color="black";}
curRow=src; curRow.style.backgroundColor="midnightblue"; curRow.style.color="white";
}
function onEvent(src){
oPopup.hide();
switch(src.operation){
//在这里为菜单项的点击事件添加处理方法
//本示例的方法只供参考,没有实现
case "edit": example(src.operation); break;
case "refresh": example(src.operation); break;
case "addrowup": example(src.operation); break;
case "addrowdown": example(src.operation); break;
case "delrow": example(src.operation); break;
case "moveup": example(src.operation); break;
case "movedown": example(src.operation); break;
default: return;
}
src.style.backgroundColor="scrollbar";
src.style.color="black";
curRow=null;
}
function example(str){
alert("您选择了"+str+"操作!");
}
</script>
<body onload="init();showMenu()">
</body>