📄 menutool.js
字号:
/*
************函数的使用说明
放到页面<head>中间
<SCRIPT language=javascript src="<%=request.getContextPath()%>/include/menuTool.js"></SCRIPT>
放到显示使用位置
<A onmouseover=showmenu(1) onmouseout=delayhidemenu() href="#"><img border="0" src="<%=request.getContextPath()%>/images/mouse-rq.gif" width="16" height="14"></a>
注意在使用时候的表格ID
页面调用函数一般放到页面的最后
var insertContext=new Array()
function showmenu(modeLayer){
//初始化数据
//插入表格内容
insertContext[0]="<input type=\"checkbox\" value=\"ON\" name=C1></input> <input type=\"hidden\" name=\"sub01_03_02_field001\" value=\"<%=SN%>\"><input type=\"hidden\" name=\"sub01_03_02_field002\" value=\"sub01_03_02\"> <input type=\"hidden\" name=\"sub01_03_02_field003\" value=\"\">";
insertContext[1]="<DIV onclick=\"getRowIndex();\"><input name=\"sub01_03_02_field004\" type=\"text\" size=\"7\" value=\"\"></DIV>";
insertContext[2]="<DIV onclick=\"getRowIndex();\"><input type=\"text\" name=\"sub01_03_02_field005\" size=\"6\" value=\"\"></DIV>";
insertContext[3]="<DIV onclick=\"getRowIndex();\"><input type=\"text\" name=\"sub01_03_02_field006\" size=\"18\" value=\"\"></DIV>";
insertContext[4]="<DIV onclick=\"getRowIndex();\"><input name=\"sub01_02_field007\" type=\"text\" size=\"24\" value=\"\"></DIV>";
insertContext[5]="<DIV onclick=\"getRowIndex();\"><input type=\"text\" name=\"sub01_03_02_field008\" size=\"11\" value=\"\"></DIV>";
//显示菜单内容
var linkset=new Array()
//一般情况
if(modeLayer=="1"){
linkset[0]="<div class='menuitems'><a href='javascript:insertTable(\"stockman\",insertContext,document.all.sub01_03_02_field003)'>添 加</a></div>"
linkset[0]+="<div class='menuitems'><a href='javascript:deleteRow(\"stockman\",3)'>删 除</a></div>"
}
showMenuLayer(event,linkset[0]);
}
函数的使用说明:
showmenu函数的参数为1,就是显示的菜单。
insertContext数组就是,要添加表格行变量的列项目。
菜单中的说明:
添加:linkset[0]中的insertTable(\"stockman\",insertContext,document.all.sub01_03_02_field003)中的stockman为表格的ID,insertContext为列的变量列表,document.all.sub01_03_02_field003是隐藏变量程序将对他进行初始化自动加1。
删除:linkset[0]中的deleteRow(\"stockman\",3) 中的stockman为表格的ID,3是表格所在变量第一行的行号。
*/
////层的显示模块 start
var ie4=document.all&&navigator.userAgent.indexOf("Opera")==-1
var ns6=document.getElementById&&!document.all
var ns4=document.layers
function showMenuLayer(e,which){
if (!document.all&&!document.getElementById&&!document.layers)
return
clearhidemenu()
menuobj=ie4? document.all.popmenu : ns6? document.getElementById("popmenu") : ns4? document.popmenu : ""
menuobj.thestyle=(ie4||ns6)? menuobj.style : menuobj
if (ie4||ns6)
menuobj.innerHTML=which
else{
menuobj.document.write('<layer name=gui bgColor=#E6E6E6 width=80 onmouseover="clearhidemenu()" onmouseout="hidemenu()">'+which+'</layer>')
menuobj.document.close()
}
menuobj.contentwidth=(ie4||ns6)? menuobj.offsetWidth : menuobj.document.gui.document.width
menuobj.contentheight=(ie4||ns6)? menuobj.offsetHeight : menuobj.document.gui.document.height
eventX=ie4? event.clientX : ns6? e.clientX : e.x
eventY=ie4? event.clientY : ns6? e.clientY : e.y
//Find out how close the mouse is to the corner of the window
var rightedge=ie4? document.body.clientWidth-eventX : window.innerWidth-eventX
var bottomedge=ie4? document.body.clientHeight-eventY : window.innerHeight-eventY
//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<menuobj.contentwidth)
//move the horizontal position of the menu to the left by it's width
menuobj.thestyle.left=ie4? document.body.scrollLeft+eventX-menuobj.contentwidth : ns6? window.pageXOffset+eventX-menuobj.contentwidth : eventX-menuobj.contentwidth
else
//position the horizontal position of the menu where the mouse was clicked
menuobj.thestyle.left=ie4? document.body.scrollLeft+eventX : ns6? window.pageXOffset+eventX : eventX
//same concept with the vertical position
if (bottomedge<menuobj.contentheight)
menuobj.thestyle.top=ie4? document.body.scrollTop+eventY-menuobj.contentheight : ns6? window.pageYOffset+eventY-menuobj.contentheight : eventY-menuobj.contentheight
else
menuobj.thestyle.top=ie4? document.body.scrollTop+event.clientY : ns6? window.pageYOffset+eventY : eventY
menuobj.thestyle.visibility="visible"
return false
}
function contains_ns6(a, b) {
//Determines if 1 element in contained in another- by Brainjar.com
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}
function hidemenu(){
if (window.menuobj)
menuobj.thestyle.visibility=(ie4||ns6)? "hidden" : "hide"
}
function dynamichide(e){
if (ie4&&!menuobj.contains(e.toElement))
hidemenu()
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
hidemenu()
}
function delayhidemenu(){
if (ie4||ns6||ns4)
delayhide=setTimeout("hidemenu()",500)
}
function clearhidemenu(){
if (window.delayhide)
clearTimeout(delayhide)
}
function highlightmenu(e,state){
if (document.all)
source_el=event.srcElement
else if (document.getElementById)
source_el=e.target
if (source_el.className=="menuitems"){
source_el.id=(state=="on")? "mouseoverstyle" : ""
}
else{
while(source_el.id!="popmenu"){
source_el=document.getElementById? source_el.parentNode : source_el.parentElement
if (source_el.className=="menuitems"){
source_el.id=(state=="on")? "mouseoverstyle" : ""
}
}
}
}
if (ie4||ns6)
document.onclick=hidemenu
////层的显示模块 end
//table editor start
var rowNum = -1; //插入表格最后一行;
function getRowIndex()
{
var e=event.srcElement;
var pRow = e.parentElement; //当前行
if(pRow.tagName == "DIV")
pRow = pRow.parentElement;
if(pRow.tagName == "TD")
pRow = pRow.parentElement;
rowNum = pRow.rowIndex+1;
}
function insertTable(stockman,insertContext,hiddenvar)
{
var otd,i;
var rowT=document.all(stockman);
//alert(rowNum);
if(rowNum == -1 || rowNum<-1 || rowNum ==null) rowNum = - 1
if(rowNum>=rowT.rows.length)rowNum=-1;
//插入行
var otr = rowT.insertRow(rowNum);
//插入列
for(i=0;i<insertContext.length;i++){
otd = otr.insertCell();
otd.className="formTd01";
otd.innerHTML=insertContext[i];
}
rowNum = -1; //插入表格最后一行
if(!hiddenvar){
//alert("该对象不存在!");
//return true;
}
else{
if(hiddenvar.length==null){
hiddenvar.value="01";
}
else{
for(i=0;i<hiddenvar.length;i++){
hiddenvar[i].value=(i<10?"0"+i:i)
}
}
}
}
function deleteRow(stockman,stockmanStartNum) //删除选中的表行,tablename是表格的id
{
var rowT=document.all(stockman);
var rowsNum=rowT.rows.length
for(i=stockmanStartNum;i<rowT.rows.length;i++) {
//alert(rowT.rows[i].cells[0].children[0].value);
if(rowT.rows[i].cells[0].children[0].checked == true){
rowT.deleteRow(i);
i = i-1;
rowsNum=rowT.rows.length ;
}
//alert(stockmanStartNum+" "+i+" "+rowT.rows[i].cells[0].innerHTML);
//alert(stockmanStartNum+" "+i+" "+rowT.rows[i].cells[0].children[0].checked);
}
}
//table editor end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -