想给dtree添加一个右击事件,无从下手
解决方案 »
- 向高手求救ssh中java.lang.NullPointerException
- 大三,想趁着这个暑假在武汉找个地方实习,希望各位前辈指点
- 如何用webwork标签逆序输出list
- 那个有下载的源代码啊
- ejb-modeler-layout.xml的作用是什么?
- 求助
- 30分求助整合apache和tomcat的mod_jk_1.2.5_2.0.47.dll文件
- 急!求解<s:Iterator property>标签问题
- 推荐一本Struts的书如何?
- 小弟弟 我要毕设了,大学一事无成,看了xml以后激动万分。想做java & xml
- 一个pager-taglib的问题,急。
- 将SpringSide3的mini-web移植到myeclipse后报错
http://www.trendskitchens.co.nz/jquery/contextmenu/jquery.contextmenu.r2.packed.js
http://jquery.com/
实现代码:
<script type="text/javascript">
$(function(){
$("#menu").contextMenu('rightmenu',{
bindings:
{
'first': function(t) {
alert('first');
},
'second': function(t) {
alert('second');
},
'third': function(t) {
alert('third');
},
'four': function(t) {
alert('four');
}
}
});
});
</script>
页面资源代码(记得引入jquery库文件与插件文件):
<div id="menu">
<font color="red">右键点击</font>
</div>
<!-- 菜单资源项,请把class定义为:contextMenu,为不显示 -->
<div class="contextMenu" id="rightmenu">
<ul>
<li id="first">
第一项
</li>
<li id="second">
第二项
</li>
<li id="third">
第三项
</li>
<li id="four">
第四项
</li>
</ul>
</div>
案例地址http://gongzhong.2009.blog.163.com/blog/static/11325526120104116855328/
function Node(id, pid, name, url, title, target, icon, iconOpen, open) {
this.id = id;
this.pid = pid;
this.name = name;
this.url = url;
this.title = title; this.target = target;
this.icon = icon;
this.iconOpen = iconOpen; this._io = open || false;
this._is = false;
this._ls = false;
this._hc = false;
this._ai = 0;
this._p;
};******
// Closes all children of a nodedTree.prototype.closeAllChildren = function(node) { for (var n=0; n<this.aNodes.length; n++) { if (this.aNodes[n].pid == node.id && this.aNodes[n]._hc) { if (this.aNodes[n]._io) this.nodeStatus(false, n, this.aNodes[n]._ls); this.aNodes[n]._io = false; this.closeAllChildren(this.aNodes[n]); } }}// Change the status of a node(open or closed)dTree.prototype.nodeStatus = function(status, id, bottom) { eDiv = document.getElementById('d' + this.obj + id); eJoin = document.getElementById('j' + this.obj + id); if (this.config.useIcons) { eIcon = document.getElementById('i' + this.obj + id); eIcon.src = (status) ? this.aNodes[id].iconOpen : this.aNodes[id].icon; } eJoin.src = (this.config.useLines)? ((status)?((bottom)?this.icon.minusBottom:this.icon.minus):((bottom)?this.icon.plusBottom:this.icon.plus)): ((status)?this.icon.nlMinus:this.icon.nlPlus); eDiv.style.display = (status) ? 'block': 'none';};// [Cookie] Clears a cookiedTree.prototype.clearCookie = function() { var now = new Date(); var yesterday = new Date(now.getTime() - 1000 * 60 * 60 * 24); this.setCookie('co'+this.obj, 'cookieValue', yesterday); this.setCookie('cs'+this.obj, 'cookieValue', yesterday);};// [Cookie] Sets value in a cookiedTree.prototype.setCookie = function(cookieName, cookieValue, expires, path, domain, secure) { document.cookie = escape(cookieName) + '=' + escape(cookieValue) + (expires ? '; expires=' + expires.toGMTString() : '') + (path ? '; path=' + path : '') + (domain ? '; domain=' + domain : '') + (secure ? '; secure' : '');};// [Cookie] Gets a value from a cookiedTree.prototype.getCookie = function(cookieName) { var cookieValue = ''; var posName = document.cookie.indexOf(escape(cookieName) + '='); if (posName != -1) { var posValue = posName + (escape(cookieName) + '=').length; var endPos = document.cookie.indexOf(';', posValue); if (endPos != -1) cookieValue = unescape(document.cookie.substring(posValue, endPos)); else cookieValue = unescape(document.cookie.substring(posValue)); } return (cookieValue);};// [Cookie] Returns ids of open nodes as a stringdTree.prototype.updateCookie = function() { var str = ''; for (var n=0; n<this.aNodes.length; n++) { if (this.aNodes[n]._io && this.aNodes[n].pid != this.root.id) { if (str) str += '.'; str += this.aNodes[n].id; } } this.setCookie('co' + this.obj, str);};// [Cookie] Checks if a node id is in a cookiedTree.prototype.isOpen = function(id) { var aOpen = this.getCookie('co' + this.obj).split('.'); for (var n=0; n<aOpen.length; n++) if (aOpen[n] == id) return true; return false;};// If Push and pop is not implemented by the browserif (!Array.prototype.push) { Array.prototype.push = function array_push() { for(var i=0;i<arguments.length;i++) this[this.length]=arguments[i]; return this.length; }};if (!Array.prototype.pop) { Array.prototype.pop = function array_pop() { lastElement = this[this.length-1]; this.length = Math.max(this.length-1,0); return lastElement; }};
var U1836P167T10D888F2423DT20081113173459=0; //U1836P167T10D888F2423DT20081113173459为全局变量ID
var oPopup=null;
var popWidth=110;
var popHeight=140;
var curRow=null;function init()
{ //页面 BODY中 ONLOAD中调用
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>'; strHTML+='<tr operation="模板列表"><td> 模板列表</td></tr>';
strHTML+='<tr operation="文章列表"><td> 文章列表</td></tr>';
strHTML+='<tr operation="增加新栏目"><td> 增加新栏目</td></tr>';
strHTML+='<tr operation="修改栏目"><td> 修改栏目</td></tr>';
strHTML+='<tr operation="删除栏目"><td> 删除栏目</td></tr>'; 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(id)
{
U1836P167T10D888F2423DT20081113173459=id;
var e=window.event;
var src=e.srcElement; oPopup.show(window.event.clientX-8, window.event.clientY-20, 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 "模板列表": example('模板列表'); break;
case "文章列表": example('文章列表'); break;
case "增加新栏目": example('增加新栏目'); break;
case "修改栏目": example('修改栏目'); break;
case "删除栏目": example('删除栏目'); break;
default: return;
}
src.style.backgroundColor="scrollbar";
src.style.color="black";
curRow=null;
}; function example(str)
{
if(str=="模板列表")
{
alert(U1836P167T10D888F2423DT20081113173459);
window.parent.mainFrame.location="model.do?act=inModel&columnId="+ U1836P167T10D888F2423DT20081113173459;
}
else if(str=="文章列表")
{
alert(U1836P167T10D888F2423DT20081113173459);
window.parent.mainFrame.location="showall.do?columnId="+ U1836P167T10D888F2423DT20081113173459;
}
else if(str=="增加新栏目")
{
alert(U1836P167T10D888F2423DT20081113173459);
window.parent.mainFrame.location="column/addcolumn.jsp?columnId="+ U1836P167T10D888F2423DT20081113173459;
}else if(str=="修改栏目")
{
alert(U1836P167T10D888F2423DT20081113173459);
window.parent.mainFrame.location="column/updatecolumn.jsp?columnId="+ U1836P167T10D888F2423DT20081113173459;
}else if(str=="删除栏目")
{
alert(U1836P167T10D888F2423DT20081113173459);
window.parent.mainFrame.location="column/deletecolumn.jsp?columnId="+ U1836P167T10D888F2423DT20081113173459;
}
} ;