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

📄 xml.js

📁 利用AJAX实现目录树
💻 JS
字号:


var curSelectColor ="A2A200";//"A2A200"; 光标按下和选择时的颜色
var curPassColor ="#d5dffd";//"A2A200"; 光标按下和选择时的颜色
	var startX, startY, endX, endY;
	var inSelecting = false;
	
function getRectOf(obj)
{
		var x=0;
		var y=0;
		var temp = obj;
		while(temp.offsetParent != null)
		{
			x += temp.offsetLeft;
			y += temp.offsetTop;
			temp = temp.offsetParent;
		}
	
	function Rect(x, y, width, height)
	{//alert("a");	
		this.x = x;
		this.y = y;
		this.width = width;
		this.height = height;
		this.cover = cover;
		this.show = show;
	}
	
	function cover(that)
	{
		if((((this.x >= that.x)&&(this.x <= that.x + that.width))||
			((this.x + this.width >= that.x)&&(this.x + this.width <= that.x + that.width))||
			((this.x < that.x)&&(this.x + this.width > that.x + that.width)))&&
			(((this.y >= that.y)&&(this.y <= that.y + that.height))||
			((this.y + this.height >= that.y)&&(this.y + this.height <= that.y + that.height))||
			((this.y < that.y)&&(this.y + this.height > that.y + that.height)))){
			return true;
		}
		return false;
	}
	
	function show()
	{
	 alert("x:" + this.x + "  y:" + this.y + " width:" + this.width + "  height:" + this.height);
	}
		
	 return new Rect(x, y, obj.offsetWidth, obj.offsetHeight);
}
			
	function mouseDown(divCal){
	 
		var divCalRect = getRectOf(divCal)
		if(event.button == 1){
			inSelecting = true;
			startX = divCal.scrollLeft + event.clientX - divCalRect.x;
			startY = divCal.scrollTop + event.clientY - divCalRect.y;
		}
		// window.alert (this)
	  }

function mouseMove(divCal,imgBox,imgPail){
		var divCalRect = getRectOf(divCal);
		imgPail.style.pixelLeft = divCal.scrollLeft + event.clientX - divCalRect.x + 10;
		imgPail.style.pixelTop = divCal.scrollTop + event.clientY - divCalRect.y - 10;

		if(event.button == 1 && inSelecting == true){//window.alert (this)
			imgBox.style.display = "block";
			if( startX < divCal.scrollLeft + event.clientX - divCalRect.x){
				imgBox.style.pixelLeft = startX - 2;
				imgBox.style.pixelWidth = divCal.scrollLeft + event.clientX - divCalRect.x - startX;
			}
			else{
				imgBox.style.pixelLeft = divCal.scrollLeft + event.clientX - divCalRect.x - 2;
				imgBox.style.pixelWidth = startX - divCal.scrollLeft - event.clientX + divCalRect.x;
			}

			if( startY < divCal.scrollTop + event.clientY - divCalRect.y){
				imgBox.style.pixelTop = startY - 2;
				imgBox.style.pixelHeight= divCal.scrollTop + event.clientY - divCalRect.y - startY;
			}
			else{
				imgBox.style.pixelTop = divCal.scrollTop + event.clientY- divCalRect.y - 2;
				imgBox.style.pixelHeight= startY - divCal.scrollTop - event.clientY + divCalRect.y;
			}
			imgBox.style.display = "block";
		}
	}
	
	function mouseUp(imgBox){
		if( inSelecting == true){
			var boxRect;
			if((imgBox.style.pixelWidth == 0)&&(imgBox.style.pixelHeight == 0)){
				boxRect = new Rect(event.clientX, event.clientY, 0, 0);
			}
			else{
				boxRect = getRectOf(imgBox);
			}

			paintRect(boxRect)

			inSelecting = false;
			imgBox.style.pixelLeft = 0;
			imgBox.style.pixelTop = 0;
			imgBox.style.pixelWidth = 0;
			imgBox.style.pixelHeight= 0;
			
			imgBox.style.display = "none";
		}
	}	
	
	function paintRect(boxRect)
	{
		var rect = getRectOf(DataGrid1.rows[0]);
		if((rect.x > boxRect.x + boxRect.width)||
			(rect.x + rect.width < boxRect.x)){
			return;
		}
		for(i=0; i<DataGrid1.rows.length; i++){
			rect = getRectOf(DataGrid1.rows[i]);
			if(rect.y > boxRect.y + boxRect.height) return;
			if((rect.y <= boxRect.y + boxRect.height)&&
				(rect.y + rect.height >= boxRect.y)){
				var currRow=DataGrid1.rows[i]
				currRow.style.backgroundColor=curSelectColor;
				//window.alert (gettype(DataGrid1.rows[i].cells[0].children[0])
				if(currRow.cells[0].children[0]!=null )
				if(currRow.cells[0].children[0].type.toLowerCase() == "checkbox" )
				  currRow.cells[0].children[0].checked=true;
			//	changeClass(DataGrid1.rows[i].recNo, curSelectColor);
			}
		}		
	}

	function mouseOver(divCal,imgPail){
		var divCalRect = getRectOf(divCal)
		imgPail.style.display = "block";
		imgPail.style.pixelLeft = divCal.scrollLeft + event.clientX - divCalRect.x + 10;
		imgPail.style.pixelTop = divCal.scrollTop + event.clientY - divCalRect.y - 10;
		//alert (imgPail.style.pixelLeft)
	}

	function mouseOut(imgPail){
		imgPail.style.display = "none";
	}  
	
				
		function rowMouseOut(item)
         {
         if(item.cells[0].children[0]==null)
            {
             item.style.background="#ffffff";  	
             return;
             }
         
            if(item.cells[0].children[0].checked)
              {item.style.backgroundColor=curSelectColor;
              }
            else
              item.style.background="#ffffff";  			
		}
		
		function rowMouseDown(item)
         { 
            item.style.background=curSelectColor;
             if(item.cells[0].children[0]==null) return;
            item.cells[0].children[0].checked=true;
            			
		}	
		
	function Rect(x, y, width, height)
	{
	/*
	/	this.x = x;
		this.y = y;
		this.width = width;
		this.height = height;
		this.cover = cover;
		this.show = show;*/
	}
	
	function cover(that)
	{
		if((((this.x >= that.x)&&(this.x <= that.x + that.width))||
			((this.x + this.width >= that.x)&&(this.x + this.width <= that.x + that.width))||
			((this.x < that.x)&&(this.x + this.width > that.x + that.width)))&&
			(((this.y >= that.y)&&(this.y <= that.y + that.height))||
			((this.y + this.height >= that.y)&&(this.y + this.height <= that.y + that.height))||
			((this.y < that.y)&&(this.y + this.height > that.y + that.height)))){
			return true;
		}
		return false;
	}
	
	function show()
	{
	 alert("x:" + this.x + "  y:" + this.y + " width:" + this.width + "  height:" + this.height);
	}
	
function XmlToTable(sXml,fileXslt)
{
	var xml  = new ActiveXObject("Msxml2.DOMDocument.3.0");
      xml.async=false;
      xml.loadXML(sXml);
      if (xml.parseError.errorCode != 0)
       {
          //WScript.Echo ("XML 文件错误 : " + xml.parseError.reason);
          return;
        }

    var xslt = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.3.0");
     xslt.async=false;
     xslt.load(fileXslt);
     if (xslt.parseError.errorCode != 0)
     {
       //WScript.Echo ("XSL 文件错误 : " + xslt.parseError.reason);
       return;
      }

    try
	{
	  //WScript.Echo (xml.transformNode(xslt.documentElement));
	  return  xml.transformNode(xslt);
	}
	catch(err)
	{
	  ;//WScript.Echo ("转换错误: " + err.number + "*" + err.description);
	}
}

	function GetTableOuterHTML(TableName)
	{
		//window.alert (TableName);
			var Table=AjaxData.GetTableOuterHTML(TableName);
			return Table.value;
			//window.alert (Table.value);
			//divDataGrid.innerHTML=Table.value;
		}	
	
	function OpenAddWin(frmWin,width,height)  
		{   
			var ret=window.showModalDialog(frmWin,window,'dialogWidth='+width +'px;dialogHeight='+height+'px;help:no;status:no')  
			return ret;
		} 
	
	function OpenEditWin(frmWin,width,height)  
	{    
		var objs = DataGrid1.getElementsByTagName("input");  
		var code,isSelect;
		isSelect=false;
        for(var i=0; i<objs.length; i++) 
        {
            if(objs[i].type.toLowerCase() == "checkbox" )              
            if(objs[i].checked)
				{ //window.alert(objs[i].parentElement.parentElement.cells[2].innerText);//children InnerHtml //innerHTML
					code=objs[i].parentElement.parentElement.cells[2].innerText;
					
					isSelect=true;
					break;
				}	
        }
        if(isSelect)
        {
            var frmEditWin=frmWin+"?code="+code
		    var ret= OpenAddWin(frmEditWin,width,height);
		    return ret;
		    }
		else
		    window.alert("您没有选择所要更新的行!");       
	} 
	
	
	
	function ButtonOver(buttonTD) 
	{
	   if(buttonTD.childNodes.length && buttonTD.childNodes[0].tagName == "IMG")
	    {
		  buttonTD.childNodes[0].className='ButtonOver';
		 
		 }
	}
	function ButtonOut(buttonTD)
	{
		if(buttonTD.childNodes.length && buttonTD.childNodes[0].tagName == "IMG")
		{
			buttonTD.childNodes[0].className='ButtonOut';
		}
	}
	function ButtonDown(buttonTD,imageOver,imageDown) 
	{
		if(buttonTD.childNodes.length && buttonTD.childNodes[0].tagName == "IMG")
		 {
		   buttonTD.childNodes[0].className='ButtonDown';
		  }
	  
	}
	function ButtonUp(buttonTD,ftbName,imageOver,imageDown)
	{
		if(buttonTD.childNodes.length && buttonTD.childNodes[0].tagName == "IMG")
			{
			  buttonTD.childNodes[0].className='ButtonUp';
			}
	}
	//删除所选择的行
	function DeleteSeleteRows(TableName)
	{//alert(TableName);
	    if (confirm("您真的删除所选择的行吗?")==false) return;
		var objs = DataGrid1.getElementsByTagName("input");				    
		for(var i=objs.length-1; i>0; i--) 
		{ 
			var CurrCheckbox=objs[i];
			if(CurrCheckbox.type.toLowerCase() == "checkbox" )              
			{
				if(CurrCheckbox.checked)
				{
					var ID=CurrCheckbox.parentElement.nextSibling.innerText;								
					var isSuccess= AjaxData.DeleteRow(TableName,ID);
					
					if(isSuccess.value)
						{
							var rowIndex=CurrCheckbox.parentElement.parentElement.rowIndex
							DataGrid1.deleteRow(rowIndex);
							if(TableName=="tInfoClass")
							DomTree.deleteItem("C"+ID);
						}
				  }				
			  }
		  }
      }
        
        //在表Table1的RowIndex位置插入一行,该行的数据来源于DataRow
			function InsertRow(Table1,ID)
			{
				if(Table1.rows.length==0||Table1==null) return;//表为空
				if(ID<0) return;
				//alert(ID);
				var LastRow=Table1.rows[Table1.rows.length-1];
				var NewRow=LastRow.cloneNode(true) ;
				NewRow.children[1].innerText=ID;//parseInt(NewRow.children[1].innerText)+1;//保证是新增加时自动加一,与数据表一致
				// alert(NewRow.children[1].innerText)
				// var Row=Table1.rows[RowIndex] ;			  
				SetRowText(NewRow);	          
				LastRow.parentNode.insertAdjacentElement('beforeEnd',NewRow);
		          
				/*下面的方法有刷新感觉,且replace方法不适合大字符串,且向divDataGrid.innerHTML重新装载的效率是否佳?所以暂不用	          
						var length=DataGrid1.rows.length;			    
						var oldRow=DataGrid1.insertRow(length).outerHTML;					
						//alert(oldRow);
						var strTable=DataGrid1.outerHTML;
						txtName.value =strTable;
						//alert(strTable);
					//  var oldRow=ThisCell.parentElement.innerHTML;
						var NewRow=AjaxData.GetRowOuterHTML().value;
					txtName.value =NewRow;
					var NewTable=strTable.replace(oldRow,NewRow);
					    
					divDataGrid.innerHTML=NewTable;		
					*/
			  
			}
			//设置行的文本,把数组DataRow的赋值给Row
			function SetRowText(Row)
			{
			  try
			  {		   
					var RowID=Row.children[1].innerText;	
					var DataRow=AjaxData.GetDataRow(RowID).value;
					alert(DataRow)
					if(DataRow==null) return;//没有数据 				
					if(DataRow.length==0) return;//没有数据 
					
					if(Row.children.length==0||Row==null) return;//行为空
					if(DataRow.length>Row.children.length) return;//
					alert(DataRow[6])
					alert(DataRow[7])
					alert(DataRow[8])
					for(var i=0;i<DataRow.length;i++)
					    if(DataRow[i]!=null)
						  Row.childNodes[i+1].innerText=DataRow[i];	
			   }
			  catch(err)
				{
					alert(err.description);//WScript.Echo ("转换错误: " + err.number + "*" + err.description);
				}
			}
			
			
			
			

⌨️ 快捷键说明

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