⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 alai_tc.js

📁 阿赖实用javascript控件程序当前包括表格控件、浮动层窗体控件、菜单控件和目录树控件(及目录树模板)几种。
💻 JS
📖 第 1 页 / 共 2 页
字号:
				td[i].style.color=fc
				td[i].style.backgroundColor=bc
			}
			curRow=tr
		}
		tc.tbl.onmouseover=function()
		{
			var e=event.srcElement;
			if(e==this){return;}
			while(e.tagName!="TR"){e=e.parentElement;}
			overRow(e)
			setSelStyle()
		}
		tc.tbl.onmouseout=function()
		{
			if(curRow==null){return}
			var td=curRow.cells
			for(var i=0;i<td.length;i++)
			{
				td[i].style.color=rowfc[i]
				td[i].style.backgroundColor=rowbc[i]
			}
			curRow=null
			tc.setColStyle(colStyle);
			tc.setRowStyle(rowStyle);
		}
		var idx=-1;
		var colfc=[],colbc=[]
		tc.ctr.onmouseover=function()
		{
			var e=event.srcElement;
			if(e.tagName!="TD"){return;}
			if(idx!=-1)
			{
				for(var i=0;i<tr.length;i++)
				{
					tr[i].cells[idx].style.color=colfc[i];
					tr[i].cells[idx].style.backgroundColor=colbc[i];
				}
			}
			idx=e.cellIndex
			for(var i=0;i<tr.length;i++)
			{
				colfc[i]=tr[i].cells[idx].currentStyle.color;
				colbc[i]=tr[i].cells[idx].currentStyle.backgroundColor;
				tr[i].cells[idx].style.color=fc;
				tr[i].cells[idx].style.backgroundColor=bc;
			}
			setSelStyle()
		}
		tc.ctr.onmouseout=function()
		{
			if(idx!=-1)
			{
				for(var i=0;i<tr.length;i++)
				{
					tr[i].cells[idx].style.color=colfc[i];
					tr[i].cells[idx].style.backgroundColor=colbc[i];
				}
			}
			tc.setColStyle(colStyle);
			tc.setRowStyle(rowStyle);
		}
	}
	tc.contextMenu=function()
	{
		var menu=function ()
		{
			var mnu=this
			mnu.item=[]
			mnu.body=document.createElement("div")
			document.body.insertAdjacentElement("afterBegin",mnu.body)
			mnu.body.style.cssText="position:absolute;z-index:10;width:120;border:2 outset;background-color:buttonface;display:none;"
			mnu.add=function(Text)
			{
				var item=document.createElement("span")
				mnu.body.insertAdjacentElement("beforeEnd",item)
				item.style.cssText="padding-top:2;padding-left:14;font-size:10pt;height:21;cursor:default;color:black;background-color:buttonface;width:100%;"
				item.innerText=Text
				mnu.item[mnu.item.length]=item
				item.onmouseover=function(){item.style.color="white";item.style.backgroundColor="darkblue";}
				item.onmouseout=function(){item.style.color="black";item.style.backgroundColor="buttonface";}
				return item
			}
			mnu.remove=function(idx){mnu.item[idx].removeNode(true);}
			mnu.show=function()
			{
				mnu.body.style.pixelTop=event.y+document.body.scrollTop
				mnu.body.style.pixelLeft=event.x+document.body.scrollLeft
				mnu.body.style.display="block"
			}
			mnu.hide=function(){mnu.body.style.display="none";}
			mnu.body.onclick=mnu.hide
		}
		var tblMenu=new menu()
		var ctrMenu=new menu()
		var ci=-1,ri=-1,curRow
		var word=""
		tdLocate=null
		var find=function()
		{
			tblMenu.hide();ctrMenu.hide();
			var w=prompt("Hi,tell me what are you looking for?",word)
			if(w=="" || w==null){return}
			w=w.toLowerCase()
			var idx=(w!=word || tdLocate==null)?(0):(tdLocate.parentElement.rowIndex)
			if(tdLocate!=null)
			{
				var c=tdLocate.currentStyle.color
				tdLocate.style.color=tdLocate.currentStyle.backgroundColor
				tdLocate.style.backgroundColor=c
			}
			for(var i=++idx;i<tr.length;i++)
			{
				var td=tr[i].cells
				for(var j=0;j<td.length;j++)
				{
					if(td[j].innerText.toLowerCase().indexOf(w)!=-1)
					{
						tdLocate=td[j]
						word=w
						tc.setRowStyle(rowStyle);
						return
					}
				}
			}
			tdLocate=null
			tc.setRowStyle(rowStyle);
		}
		tc.tbl.onmousedown=function()
		{
			tblMenu.hide();ctrMenu.hide();
			if(event.button==2)tblMenu.show();
			else if(event.button==1)tblMenu.hide();
			var e=event.srcElement
			if(e.tagName=="TD"){ci=e.cellIndex;ri=e.parentElement.rowIndex;}
			else{ci=-1;ri=-1;}
			tr=tc.tbl.rows
		}
		tc.ctr.onmousedown=function()
		{
			tblMenu.hide();ctrMenu.hide();
			if(event.button==2)ctrMenu.show();
			else if(event.button==1)ctrMenu.hide();
			var e=event.srcElement
			if(e.tagName=="TD")ci=e.cellIndex;else ci=-1;
			ri=-1
			tr=tc.tbl.rows
		}
		tc.tbl.oncontextmenu=new Function("event.returnValue=false");
		tc.ctr.oncontextmenu=new Function("event.returnValue=false");
		tc.tblMenu=tblMenu
		tc.ctrMenu=ctrMenu
		tblMenu.add("上移一行").onclick=function(){if(ri==-1 || ri==0)return;tr[ri].swapNode(tr[ri-1]);tc.setRowStyle(rowStyle);}
		tblMenu.add("下移一行").onclick=function(){if(ri==-1 || ri==tr.lenght-1)return;tr[ri].swapNode(tr[ri+1]);tc.setRowStyle(rowStyle);}
		tblMenu.add("删除当前行").onclick=function(){if(ri==-1)return;tc.tbl.deleteRow(ri);tc.setRowStyle(rowStyle);}
		ctrMenu.add("升序排序").onclick=function()
		{	if(ci==-1)return;
			tblSort(tc.tbl,ci,"ASC",dType[ci]);
			tc.setRowStyle(rowStyle);
			sortBy[ci]="DESC";
			tr=tc.tbl.rows
		}
		ctrMenu.add("降序排序").onclick=function()
		{	if(ci==-1)return;
			tblSort(tc.tbl,ci,"DESC",dType[ci]);
			tc.setRowStyle(rowStyle);
			sortBy[ci]="ASC";
			tr=tc.tbl.rows
		}
		ctrMenu.add("左移一列").onclick=function()
		{	if(ci==-1 || ci==0)return;
			tc.col[ci].swapNode(tc.col[ci-1]);
			for(var i=0;i<tr.length;i++)tr[i].cells[ci].swapNode(tr[i].cells[ci-1]);
			var tmp=tc.col[ci];tc.col[ci]=tc.col[ci-1];tc.col[ci-1]=tmp;
			var tmp=dType[ci];dType[ci]=dType[ci-1];dType[ci-1]=tmp;
		}
		ctrMenu.add("右移一列").onclick=function()
		{	if(ci==-1 || ci==tc.col.length-1)return;
			tc.col[ci].swapNode(tc.col[ci+1]);
			for(var i=0;i<tr.length;i++)tr[i].cells[ci].swapNode(tr[i].cells[ci+1]);
			var tmp=tc.col[ci];tc.col[ci]=tc.col[ci+1];tc.col[ci+1]=tmp;
			var tmp=dType[ci];dType[ci]=dType[ci+1];dType[ci+1]=tmp;
		}
		ctrMenu.add("删除当前列").onclick=function()
		{	if(ci==-1)return;
			tc.ctr.rows[0].deleteCell(ci);
			for(var i=0;i<tr.length;i++)tr[i].deleteCell(ci);
			tc.ctr.setAttribute("width",tc.tbl.offsetWidth);
			tc.col.remove(ci);dType.remove(ci);
		}
		ctrMenu.add("查找").onclick=find
		tblMenu.add("查找").onclick=find
	}
	
	tc.doResize=function()
	{
		var x,tdW,tblW,ctrCol,isSort,isSize
		tc.tbl.style.tableLayout="fixed"
		for(var i=0;i<tr.length;i++)for(var j=0;j<tr[i].cells.length;j++)tr[i].cells[j].style.overflowX="hidden";
		for(var i=0;i<tc.col.length;i++)
		{
			tc.col[i].onmouseover=function(){if(!isSize)ctrCol=this;}
			//tc.col[i].onmouseout=function()	{if(!(event.toElement==tc.ctr || event.toElement.parentElement==tc.ctr || event.toElement.parentElement.parentElement==tc.ctr))isSize=false;}
			tc.col[i].onclick=function()
			{
				if(isSize){isSize=false;return;}
				var idx=this.cellIndex
				tblSort(tc.tbl,idx,sortBy[idx],dType[idx]);
				sortBy[idx]=(sortBy[idx]=="ASC")?"DESC":"ASC";
				tc.setRowStyle(rowStyle);
				tr=tc.tbl.rows
			}
			tc.col[i].onmousedown=function()
			{
				this.setCapture();
				isSort=this.offsetWidth-event.offsetX>8 && event.offsetX>5;
				if(isSort){	this.style.borderStyle="inset";}
				else{
					var i=this.cellIndex
					ctrCol=(event.offsetX<=5 && i!=0)?tc.col[i-1]:tc.col[i]
					x=event.x;
					tdW=ctrCol.offsetWidth;
					tblW=tc.ctr.offsetWidth;
					isSize=true;
					}
			}
			tc.col[i].onmouseup=function(){this.style.borderStyle="outset";this.releaseCapture();}
			tc.col[i].onmousemove=function()
			{
				if(isSize)
				{
					var idx=ctrCol.cellIndex;
					var iSpan=event.x-x;
					tc.ctr.style.pixelWidth=tblW+iSpan
					ctrCol.setAttribute("width",tdW+iSpan);
					tc.tbl.setAttribute("width",tblW+iSpan);
					for(var i=0;i<tr.length;i++){if(tr[i].cells[idx])tr[i].cells[idx].setAttribute("width",tdW+iSpan);}
					return;
				}
				isSort=this.offsetWidth-event.offsetX>8 && event.offsetX>5;
				this.style.cursor=isSort?"default":"move"
			}
		}
	}
return tc
}
catch(e){
	tc.err="alai_tc cause run time error!\nError number:"+e.number+".\nError description:"+e.description;
	tc.err+="\n    -- \nYou can send the case and error description message to A@lai.com.cn for support or visit http://www.9499.net to get the last release!"
	alert(tc.err);
	return tc;
}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -