|
QQ:77182997
MSN:xiaofengNET@hotmail.com
Email:xiaofengNET@163.com
網址:http://www.d369.NET
請保留版權 謝謝合作
版本:V 1.6.1
/*****************************************************************************************
/*
為XiaoFeng.System添加一方法Scroll [2009-02-18] V 1.4.1
為Array添加一方法Index [2009-04-09] V 1.4.2
為String 添加TrimStart,TrimEnd,Trim,StartsWith,EndsWith函數 [2009-04-09] V 1.4.3
為 Number 添加 toFixed 方法 實現 數字保留小數點后幾位 [2009-04-17] V 1.4.4
FileType 獲得文件的名稱及文件的后綴名 [2009-04-20] V 1.4.5
XiaoFeng.Dialog 打開選擇窗口及保存窗 [2009-05-28] V 1.4.6
通過Object類為每個對象添加方法getType 獲得對象的父結點 getParent[2009-06-04] V 1.4.7
更新方法 getQuery(s) U默認為當前地址欄地址,s為傳進來要提取的參數 getQuery(U,s) U 為傳進來的地址 s 為傳進來要提取的參數 [2009-06-08] V 1.4.8
為String 添加兩 方法 wTh全角轉換為半角 和 hTw半角轉換為全解 [2009-06-08] V 1.4.8
更改了ajax類中的 當正在處理這段時間內的一個方法 ajax.Fun = function(){},以及判斷服務器處理程序是否出錯的一屬性 ajax.Error [2009-06-09] V 1.4.9
重新寫了String,Array,Object,Element的方法 [2009-06-12] V 1.5.0
添加了捕捉事件源 getElement XiaoFeng.getElement [2009-06-12] V 1.5.1
更新了 加載XML函數 兼容 FF IE LoadXml() [2009-06-12] V 1.5.2
添加功能 無限級下拉列表 SelectClass [2009-06-13] V 1.6.0
更新了 無限級下拉列表的 選擇為空時 選擇的值 為上一級下拉列表的值 [2009-06-13] V 1.6.1
*/
/*========================================================================================
框架核心內容--------【基礎工具類】
========================================================================================
*/
if(!window.XiaoFeng || !XiaoFeng || typeof XiaoFeng == "undefined")var XiaoFeng = window.XiaoFeng = new Object();
var Prototype = {
Version: "1.4.9",
ScriptFragment: '(?:<script.*?>)((/n|/r|.)*?)(?:<//script>)',
emptyFunction: function(){},
K: function(e){return e}
}
/*========================================================================================
【為Object類添加靜態方法】
創建于[2008-08-13]
為Object類添加靜態方法:extend
*/
Object.extend = function(destination,source){
for(property in source)destination[property] = source[property];
return destination;
}
//通過Object類為每個對象添加方法extend
Object.prototype.extend = function(object){return Object.extend.apply(this,[this,object]);}
/*===========================================================================================
【給數組添加屬性】
[創建于2009-06-12]
對數組添加附加屬性
*/
Object.extend(Array.prototype,{
remove : function(N){//移除指定的元素
if(isNaN(N)||N>this.length)return false;
for(var i=0,n=0;i<this.length;i++)if(i!=N)this[n++] = this[i];
this.length -= 1;
},
add : function(v){//添加一數組元素
for(var i=0;i<this.length;i++)
if(this[i].toString() == v.toString()) break;
this.push(v);
},
index : function(s){//指定數組中元素的索引
var FlagIndex = -1;
for(var i = 0;i < this.length; i++)
if(this[i].toString() == s.toString()){FlagIndex = i; break;}
return FlagIndex;
},
first : function(){return this[0];},//數組中第一個元素
last : function(){return this[this.length - 1];},//數組中最后一個元素
clear : function(){this.length = 0; return this;}//清空數組中的元素
});
/*===========================================================================================
【給字符串添加屬性】
[創建于2009-06-12]
給字符串加附加屬性
*/
Object.extend(String.prototype,{
len : function(){return this.replace(/[^/x00-/xff]/g,"ya").length;},//字符串的長度,一個漢字為兩個
Length : function(){
var M = 0;
for(var i=0;i<this.length;i++){
if(this.charCodeAt(i) > 255)
M = M + 2;
else
M = M + 1;
}
return M;
},
Trim : function(s){return this.TrimStart(s).TrimEnd(s);},//清空開始與結尾的指定字符
TrimStart : function(s){//清空開始的指定字符
if(!s)s = "http://s+";
var trimStartStr = new RegExp("^("+ s +")+","g");
return this.replace(trimStartStr,"");
},
TrimEnd : function(s){//清空結尾的指定字符
if (!s)s = "http://s+";
var trimEndStr = new RegExp("("+ s +")+$","g");
return this.replace(trimEndStr,"");
},
StartsWith : function(s){
if (!s)s = "http://s";
var startsWithStr = new RegExp("^("+ s +")","g");
return startsWithStr.test(this);
},
EndsWith : function(s){
if (!s)s = "http://s";
var endsWithStr = new RegExp("("+ s +")$","g");
return endsWithStr.test(this);
},
wTh : function(){//全角轉換半角
var s = "";
for(var i = 0;i < this.length; i++)
s += this.charCodeAt(i) >= 65248?String.fromCharCode(this.charCodeAt(i) - 65248):this.charAt(i);
return s;
},
hTw : function(){//半角轉換全角
var s = "";
for(var i = 0;i < this.length; i++)
s += this.charCodeAt(i) < 65248?String.fromCharCode(this.charCodeAt(i) + 65248):this.charAt(i);
return s;
},
LeftStr : function(M){//左邊指定長度字符
if(this.Length() > M){
var str = "";
for(var i=0;i<this.length;i++){
if(this.charCodeAt(i) > 255)
M -= 2;
else
M -= 1;
str += this.substring(i,i+1);
if(M <= 0)break;
}
return str + "...";
}else
return this;
},
stripTags : function(){return this.replace(/<//?[^>]+>/gi, '');}
});
/*===========================================================================================
【取得數字小數點后幾位】
[創建于2009-06-12]
為數字添加附加屬性
*/
Object.extend(Number.prototype,{
toFixed : function(N){//格式化數字
if(arguments.length == 0)N = 2;
with(Math){var m = pow(10,Number(N));var s = (round(this*m)/m).toString();}
if(s.indexOf('.') < 0){
s += ".";
s += "000000000000000000000000000000";
}
return s.substr(0,s.indexOf('.') + N + 1);
}
});
/*========================================================================================
【獲取一個指定ID的結點】
創建于[2005-05-03]
document.getElementById(Id)獲取一個指定ID的結點,是這個方法的快捷方式和擴展可以指定多個參
數返回一個對象數組。參數也不一定是ID也可以是對象本身的引用,例如$("id")等價于$($("id"))
*/
var $ = XiaoFeng.$ = function(){
var elements = new Array();
for(var i=0;i<arguments.length;i++){
var element = arguments[i];
if (typeof(element) == "string") element = document.getElementById?document.getElementById(element):document.all.element
if (arguments.length==1) return element;
elements.push(element);
}
return elements;
}
/*========================================================================================
【獲取一個指定ID的結點】
創建于[2005-05-03]
document.getElementsByName(id)獲取一個指定ID的名稱集,是這個方法的快捷方式和擴展可以指定多個參數返回一個對象數組
*/
var $N = XiaoFeng.$N = function(){
var elements = new Array();
for(var i=0;i<arguments.length;i++){
var element=arguments[i];
if (typeof(element) == "string") element = document.getElementsByName?document.getElementsByName(element):document.all.element;
if (arguments.length==1) return element;
elements.push(element);
}
return elements;
}
/*========================================================================================
【獲取一個指定TagName的結點】
創建于[2005-05-03]
document.getElementsByTagName(TagName)獲取一個指定TagName的名稱集,是這個方法的快捷方式和擴展可以指定多個參數返回一個對象數組
*/
var $T = XiaoFeng.$T = function(){
var elements = new Array();
for(var i=0;i<arguments.length;i++){
var element = arguments[i];
if (typeof(element) == "string") element = document.getElementsByTagName(element);
if (arguments.length==1) return element;
elements.push(element);
}
return elements;
}
/*========================================================================================
【創建一個元素】
創建于[2008-06-18]
*/
var $C = XiaoFeng.$C = function(){return document.createElement(arguments[0]);}
/*===========================================================================================
【轉換數組】
創建于[2008-08-13]
*/
var $A = XiaoFeng.$A = function(a){return a?Array.apply(null,a):new Array;}
/*===========================================================================================
【抓取事件源】
創建于[2008-08-13]
*/
var getElement = XiaoFeng.getElement = function(){
if(arguments.length == 0)
return event.srcElement;
else
return document.all?arguments[0].srcElement:arguments[0].target;
}
/*========================================================================================
【為Object類添加事件及卸載事件及鼠標坐標】
創建于[2008-10-09]
為Object類添加事件及卸載事件及鼠標坐標:
*/
Object.extend(Object.prototype,{
addEvent : function(a, b, c, d){
//添加函數
if(a.attachEvent)a.attachEvent(b[0], c);
else a.addEventListener(b[1] || b[0].replace(/^on/, ""), c, d || false);
return c;
},
delEvent : function(a, b, c, d){
if(a.detachEvent) a.detachEvent(b[0], c);
else a.removeEventListener(b[1] || b[0].replace(/^on/, ""), c, d || false);
return c;
},
Event : function(){//獲取Event
return window.event ? window.event : (function (o){
do{
o = o.caller;
} while (o && !/^/[object[ A-Za-z]*Event/]$/.test(o.arguments[0]));
return o.arguments[0];
})(this.reEvent);
},
Scroll : function(){
return {
Left : document.body.scrollLeft == 0?document.documentElement.scrollLeft:document.body.scrollLeft,
Top :document.body.scrollTop == 0?document.documentElement.scrollTop:document.body.scrollTop
};
}
});
/*========================================================================================
【判斷瀏覽器及其版本號】
[創建于2009-06-12]
*/
XiaoFeng.userAgent = function(){
var ua = navigator.userAgent.toLowerCase();
if(window.ActiveXObject)return {name : "IE",ver : ua.match(/msie ([/d.]+)/)[1]}
if(document.getBoxObjectFor)return {name : "Firefox",ver : ua.match(/firefox//([/d.]+)/)[1]}
if(window.MessageEvent && !document.getBoxObjectFor)return {name : "Chrome",ver : ua.match(/chrome//([/d.]+)/)[1]}
if(window.opera)return {name : "Opera",ver : ua.match(/opera.([/d.]+)/)[1]}
if(window.openDatabase)return {name : "Safari",ver : ua.match(/version//([/d.]+)/)[1]}
return {name : "Other",ver : 0}
}
/*========================================================================================
【鼠標的相對坐標】
[創建于2008-10-06]
*/
var Event = function(){
var e = Object.Event();
var o = {x : 0,y : 0};
switch(arguments[0]){
case 0 :/*鼠標的相對位置*/
o.x = e.clientX;
o.y = e.clientY;
break;
case 1 :/*鼠標的絕對位置*/
o.x = e.clientX + Object.Scroll().Left;
o.y = e.clientY + Object.Scroll().Top;
break;
default:/*鼠標的相對位置*/
o.x = e.clientX;
o.y = e.clientY;
break;
}
return o;
}
/*========================================================================================
【Ajax創建類】
創建于[2008-05-30]
更新于[2009-06-09]
var ajax = new AjaxRequest();
ajax.Url = "Test.ASPx";
ajax.Content = "";
ajax.Fun = function(){alert("提取中../");}
ajax.CallBack = function(e){
//操作代碼
var XmlDoc=e.responseText;
var XmlDoc=e.responseXML;
var Roots=XmlDoc.documentElement.childNodes;
alert(Roots[0].childNodes[0].text);
}
ajax.Send();
*/
XiaoFeng.Ajax = AjaxRequest;
function AjaxRequest(){
var xmlhttp = false;
var self = this;
this.Method = "post";
this.Url = "";
this.Content = "";
this.Async = true;
this.Fun = function(){return;};
this.CallBack = function(obj){return;}
this.Error = null;
this.Create = function(){//創建XMLHttpRequest
if(typeof(window.XMLHttpRequest)!="undefined"){
xmlhttp = new XMLHttpRequest();
if(xmlhttp.overrideMimeType)xmlhttp.overrideMimeType("text/html");
}else if(window.ActiveXObject){
var Versions = ["MSXML2.XMLHttp.5.0","MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0","MSXML2.XMLHttp","Microsoft.XMLHttp"];
for(var i=0;i<Versions.length;i++){
try{
var XmlHttp = new ActiveXObject(Versions[i]);
xmlhttp = XmlHttp;
}catch(Error){
if(i == (Versions.length-1))alert("出錯:創建服務器對象實例失敗.");//瀏覽器問題//拋出Error.description
}
}
}
return xmlhttp;
}
this.Send = function(){
if(this.Url == ""){alert("處理地址不能為空!");}
xmlhttp = this.Create();
xmlhttp.open(this.Method,this.Url,true);
if(this.Method == "post")xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlhttp.onreadystatechange = function(){
if(xmlhttp.readyState == 4){
if(xmlhttp.status == 200){
self.CallBack(xmlhttp);
}else{
alert("出錯:錯誤代碼["+ xmlhttp.status +"]");
self.Error = "服務器出錯["+ xmlhttp.status +"].";
clipboardData.setData("text",self.Url+"?"+self.Content);
self.CallBack(self);
}
}else
self.Fun();
}
if(this.Method.toLowerCase() == "post")
xmlhttp.send(this.Content);
else
xmlhttp.send(null);
}
}
/*========================================================================================
【創建XML對象類】
[創建于2008-04-09]
var Http_Request=false;
*/
function CreateAjax(){
var Ajax_Obj;
if(typeof(window.XMLHttpRequest) != "undefined"){
Ajax_Obj = new XMLHttpRequest();
if(Ajax_Obj.overrideMimeType)Ajax_Obj.overrideMimeType("text/html");
}else if(window.ActiveXObject){
var Versions = ["MSXML2.XMLHttp.5.0","MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0","MSXML2.XMLHttp","Microsoft.XMLHttp"];
for(var i=0;i<Versions.length;i++){
try{
var XmlHttp=new ActiveXObject(Versions[i]);
Ajax_Obj = XmlHttp;
}catch(Error){
if(i == (Versions.length-1))alert("出錯:創建服務器對象實例失敗[瀏覽器問題].");//瀏覽器問題//拋出Error.description
}
}
}
return Ajax_Obj;
}
/*========================================================================================
【加載XML操作類】
[創建于2009-06-12]
*/
function LoadXml(Path){
if(XiaoFeng.userAgent().name == "Firefox"){
var Dom = document.implementation.createDocument("", "", null);
Dom.async = false;
Dom.load(Path);
}else{
Dom = new ActiveXObject("Microsoft.XMLDOM");
Dom.async = false;
Dom.load(Path);
}
return Dom;
}
/*========================================================================================
【Cookies操作類】
[創建于2008-04-09]
*/
var Cookies = {
GetVal:function(offset){//獲得Cookie解碼后的值
var endstr = document.cookie.indexOf(";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
},
Add:function(name,value,hours){//設定Cookie值
var expire = "";
if(hours != null){
expire = new Date((new Date()).getTime() + hours * 3600000);
expire = "; expires=" + expire.toGMTString();
}
document.cookie = name + "=" + escape(value) + expire;
},
Del:function(name){//刪除Cookie
var exp = new Date();
exp.setTime(exp.getTime() - 1);
var cval = GetCookie (name);
document.cookie = name + "=" + cval + "; expires="+ exp.toGMTString();
},
Get:function(name){//獲得Cookie的原始值
var cookieValue = "";
var search = name + "=";
if(document.cookie.length > 0){
offset = document.cookie.indexOf(search);
if (offset != -1){
offset += search.length;
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
cookieValue = unescape(document.cookie.substring(offset, end))
}
}
return cookieValue;
},
get:function(name){/*獲取Cookie的原始值 注 在這里主要是對應C#里面的Cookies數組*/
var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
var r = Cookies.Get("HTGL").match(reg);
if (r != null) return unescape(r[2]);
return "";
}
}
/*//======================================================================================
//【獲得對象實際坐標】
[創建于2008-04-09]
*/
function getDim(e){
var rd = {x:0,y:0};
do{
rd.x += e.offsetLeft;
rd.y += e.offsetTop;
e = e.offsetParent;
}while(e)
return rd;
}
/*//======================================================================================
//【獲得對象的父結點】
[創建于2008-06-04]
*/
function getParent(o,N){
var e = new Object();
e = o;
do{
e = e.parentNode;
try{if(e.tagName.toLowerCase() == N.toLowerCase())break;}catch(e){break;}
}while(e)
return e;
}
/*//======================================================================================
//【獲得對象實際四角坐標】
[創建于2008-10-09]
*/
function getInfo(o){//取得坐標
var to = new Object();
to.left = to.right=to.top=to.bottom=0;
var twidth = o.offsetWidth;
var theight = o.offsetHeight;
do{
to.left += o.offsetLeft;
to.top += o.offsetTop;
o = o.offsetParent;
}while(o != document.body)
to.right = to.left + twidth;
to.bottom = to.top + theight;
return to;
}
/*//======================================================================================
//【獲得對象與指定字符匹配的對象】
[創建于2008-10-09]
*/
function getObj(o,s){
f = false;
while(o != document.body){
if(o.id.toLowerCase().indexOf(s) != -1){
f = true;
break;
}
o = o.offsetParent;
}
return f;
}
/*========================================================================================
【獲得參數值】
[創建于2008-06-08]
*/
var getQuery = XiaoFeng.getQuery = function(){
if(arguments.length == 0)return null;
if(arguments.length == 1){
var reg = new RegExp("(^|&)"+ arguments[0] +"=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if (r!=null) return unescape(r[2]);
return null;
}else{
var Reg = new RegExp(arguments[1] +"=//w+","gi");
try{return arguments[0].match(Reg).toString().split(",")[0].split("=")[1];}catch(e){return null;}
}
}
/*========================================================================================
【拖動函數】
創建于[2008-04-09]
*/
var Drag = XiaoFeng.Drag = function(o){
var x,y;
x = getDim(o).x;
y = getDim(o).y;
var deltaX = event.clientX - x;
var deltaY=event.clientY - y;
var drag = true;
o.style.filter = "Alpha(Opacity=60)";
o.onmousemove = function(){
if(drag){
o.style.left=(event.clientX - deltaX) + "px";
o.style.top=(event.clientY - deltaY) + "px";
if(event.clientX - deltaX <= 0)o.style.left = 0 + "px";
if(event.clientY - deltaY <= 0)o.style.top = 0 + "px";
if(event.clientX - deltaX + o.offsetWidth >= XiaoFeng.System.Size(0).x)o.style.left = (XiaoFeng.System.Size(0).x - o.offsetWidth) + "px";
if(event.clientY - deltaY + o.offsetHeight >= XiaoFeng.System.Size(0).y)o.style.top = (XiaoFeng.System.Size(0).y - o.offsetHeight) + "px";
o.setCapture();
}
}
o.onmouseup = function(){
o.style.filter = "Alpha(Opacity=100)";
drag = false;
o.releaseCapture();
}
}
/*========================================================================================
【字符轉換類】
創建于[2008-04-09]
更新于[2008-06-02]
*/
var StrToHtml = {
sTh:function(s){
s = s.replace(/</gi,"<");
s = s.replace(/>/gi,">");
s = s.replace(/"/gi,"/"");
s = s.replace(/&/gi,"&");
s = s.replace(/ /gi," ");
return s;
},
hTs:function(s){
s = s.replace(/</gi,"<");
s = s.replace(/>/gi,">");
s = s.replace(////gi,""");
s = s.replace(/&/gi,"&");
s = s.replace(/ /gi," ");
return s;
},
bTy:function(s){
s = s.replace(//[/gi,"<");
s = s.replace(//]/gi,">");
return s;
},
yTb:function(s){
s = s.replace(/</gi,"[");
s = s.replace(/</gi,"[");
s = s.replace(/>/gi,"]");
s = s.replace(/>/gi,"]");
s = s.replace(/ /gi," ");
return s;
}
}
/*===========================================================================================
【獲得窗體的寬高】
主要是一些系統方法
*/
XiaoFeng.System = {
Event : function(){
var e = Object.Event();
var o = {x : 0,y : 0};
switch(arguments[0]){
case 0 :/*鼠標的相對位置*/
o.x = e.clientX;
o.y = e.clientY;
break;
case 1 :/*鼠標的絕對位置*/
o.x = e.clientX + Object.Scroll().Left;
o.y = e.clientY + Object.Scroll().Top;
break;
default:/*鼠標的相對位置*/
o.x = e.clientX;
o.y = e.clientY;
break;
}
return o;
},
Size : function(){//【獲得窗體的寬高】
var s = {x : 0,y : 0};
if(window.innerWidth){
s.x = window.innerWidth;
s.y = window.innerHeight;
}else if(document.compatMode=='CSS1Compat'){
if(arguments[0] == 1){
s.x = document.body.clientWidth;
s.y = document.body.clientHeight;
}else if(arguments[0] == 2){
s.x = parseInt(document.documentElement.clientWidth) + parseInt(document.documentElement.scrollLeft);
s.y = parseInt(document.documentElement.clientHeight) + parseInt(document.documentElement.scrollTop);
}else{
s.x = document.documentElement.clientWidth;
s.y = document.documentElement.clientHeight;
}
}else if(document.body){
if(arguments[0] == 1){
s.x = document.body.scrollWidth;
s.y = document.body.scrollHeight
}else if(arguments[0] == 2){
s.x = document.body.clientWidth + document.body.scrollLeft;
s.y = document.body.clientHeight + document.body.scrollTop;
}else{
s.x = document.body.clientWidth;
s.y = document.body.clientHeight;
}
}
return s;
},
Scroll : function(){//【獲得窗體的滾動條】
var s = {x : 0,y : 0};
if(document.compatMode=='CSS1Compat'){
s.x = document.documentElement.scrollTop;
s.y = document.documentElement.scrollLeft;
}else if(document.body){
s.x = document.body.scrollTop;
s.y = document.body.scrollLeft;
}
return s;
},
getRnd : function(){return Math.floor(Math.random()*1000000);}
}
/*===========================================================================================
【獲得文件的名稱及文件的后綴名】
[2009-04-20]
*/
function FileType(FName){
FName = FName.replace(////gi,"/");
FName = FName.substr(FName.lastIndexOf("/") + 1);
return {Name : FName.substr(0,FName.indexOf(".")),Type : FName.substr(FName.indexOf(".") + 1)};
}
/*===========================================================================================
【打開選擇窗口及保存窗口】
[2009-05-28]
第一種方法:
var dialog = new XiaoFeng.Dialog("請選擇文件","txt 文件(*.txt)|*.txt|所有文件(*.*)|*.*",".txt");
第二種方法:
var dialog = new XiaoFeng.Dialog({
Title : "請選擇文件",
Filter : "txt 文件(*.txt)|*.txt|所有文件(*.*)|*.*",
DefaultExt : ".txt"
});
dialog.Open();
注:參數可以不填寫,則為默認的.
*/
XiaoFeng.Dialog = function(){
this.DialogTitle = "請選擇要打開的文件";
this.DialogFilter = "Excel 文件(*.xls)|*.xls|所有文件(*.*)|*.*";
this.DialogDefaultExt = ".xls";
this.Query = arguments;
var self = this;
this.Init = function(){
if(typeof self.Query[0] == "string"){
self.DialogTitle = self.Query[0]?self.Query[0]:self.DialogTitle;
self.DialogFilter = self.Query[1]?self.Query[1]:self.DialogFilter;
self.DialogDefaultExt = self.Query[2]?self.Query[2]:self.DialogDefaultExt;
}else if(typeof self.Query[0] == "object"){
self.DialogTitle = self.Query[0].Title?self.Query[0].Title:self.DialogTitle;
self.DialogFilter = self.Query[0].Filter?self.Query[0].Filter:self.DialogFilter;
self.DialogDefaultExt = self.Query[0].DefaultExt?self.Query[0].DefaultExt:self.DialogDefaultExt;
}
try{
if(!$("Dialog_OpenSave")){
var _Dialog_Open = $C("object");
_Dialog_Open.id = "Dialog_OpenSave";
_Dialog_Open.classid = "CLSID:F9043C85-F6F2-101A-A3C9-08002B2F49FB";
_Dialog_Open.style.display = "none";
document.body.appendChild(_Dialog_Open);
}
$("Dialog_OpenSave").CancelError = true;
}catch(e){}
}
this.Open = function(){
$("Dialog_OpenSave").DialogTitle = this.DialogTitle;
$("Dialog_OpenSave").Filter = this.DialogFilter;
$("Dialog_OpenSave").DefaultExt = this.DialogDefaultExt;
$("Dialog_OpenSave").ShowOpen();
return $("Dialog_OpenSave").FileName;
}
this.Save = function(){
$("Dialog_OpenSave").DialogTitle = this.DialogTitle.replace("打開","保存");
$("Dialog_OpenSave").Filter = this.DialogFilter;
$("Dialog_OpenSave").DefaultExt = this.DialogDefaultExt;
$("Dialog_OpenSave").ShowSave();
return $("Dialog_OpenSave").FileName;
}
this.Init();
}
/*===========================================================================================
【無限級下拉列表】
[2009-06-13]
在要放置下拉列表的地方放置一控件,一般為隱藏域 <input type="hidden" name="ClassId" id="ClassId" />
以XML為數據源可以用直接調用 XML 形式
var XMLDOM = LoadXml("CreateXML.ashx?RootId=15&sd=101");
Root = XMLDOM.documentElement;
也可以用Ajax調出數據源
var ajax = new XiaoFeng.AjaxRequest();
ajax.Url = "CreateXML.ashx?RootId=15&sd=101";
ajax.CallBack = function(e){
if(e.Error != "undefined")return;
var Root = e.responseXML.documentElement;
}
var ClassSelect = new SelectClass();
ClassSelect.Source = Root;
ClassSelect.Name = "ClassId";
ClassSelect.FirstOption = [["==請選擇==","0"]];
ClassSelect.SelectFirst = true;
ClassSelect.Fun = function(e){}
ClassSelect.Select = "101";
ClassSelect.Run();
參數說明:Source 為本下拉列表數據源 為 XMLDOM
Name 為隱藏控件ID 一般為隱藏域
FirstOption 為下拉列表第一行顯示的文字,如果想給每個都有不同的可以設置多個 例如[["==請選擇所在的省份==","0"],["==請選擇所在的市份==","0"],["==請選擇所在的縣份==","0"]] 如果 FirstOption = "" 或 FirstOption = [] 則不顯示這些文字 默認 為[["==請選擇==",""]]
SelectFirst 為是加載完后是否顯示要設置的文字 true 為顯不 false 為顯示數據第一行或設置的行 默認為 true
Fun 此函數為每個下拉列表的onchange選擇事件觸發接口函數
Select 為已經選擇的屬性 默認為""
Run 為運行此類別
*/
var SelectClass = XiaoFeng.SelectClass = function(){
this.Name = "";
this.Source = new Object();
this.FirstOption = [["==請選擇==","0"]];
this.SelectFirst = true;
this.Select = "";
this.Fun = function(e){return;}
this.Run = function(){
if(!$(this.Name)){
var _Input = $C("input");
_Input.type = "hidden";
_Input.name = this.Name;
_Input.id = this.Name;
document.body.appendChild(_Input);
}
$(this.Name).value = this.Select;
if(typeof this.Source == "object")
if(this.Source.hasChildNodes){
this.CreateSelect(this.Source);
if(this.Select == ""){
var __Select = $(this.Name).parentNode.getElementsByTagName("select");
if(this.SelectFirst)
$(this.Name).value = __Select[__Select.length - 1].value;
else
$(this.Name).value = __Select[__Select.length - 1].options[1].value;
}
}else{
var _Span = $C("span");
_Span.innerHTML = "數據源為空。";
$(this.Name).parentNode.appendChild(_Span);
}
else{
var _Span = $C("span");
_Span.innerHTML = "數據源出錯。";
$(this.Name).parentNode.appendChild(_Span);
}
}
this.CreateSelect = function(node){
if(!node.hasChildNodes){this._SelectFirstName();return;}
var Select = $C("select");
Select.id = Select.name = "select_"+ (new Date().getTime());
var _f = false,_s = 0;
if(typeof this.FirstOption == "string")this.FirstOption = [];
if(typeof this.FirstOption == "object" && this.FirstOption.length > 0)
Select.add(this.CreateOption("==請選擇==","0",false));
for(var i = 0;i < node.childNodes.length; i++){
if(node.childNodes[i].getAttribute("s") == null){_f = false;}else{_f = true;_s = i;}
Select.add(this.CreateOption(node.childNodes[i].getAttribute("Name"),node.childNodes[i].getAttribute("Id"),_f));
}
$(this.Name).parentNode.insertBefore(Select,$(this.Name));
if(_s > 0)
this.CreateSelect(node.childNodes[_s]);
else{
this.CreateSelect(node.childNodes[0]);
if(this.SelectFirst)
if(this.FirstOption.length == 0)
Select.options[0].selected = true;
else
Select.options[1].selected = true;
}
}
this.CreateOption = function(t,v,f){
var OptionSub = new Option();
OptionSub.text = t;
OptionSub.value = v;
if(f)OptionSub.selected = f;
return OptionSub;
}
this._SelectFirstName = function(){
var _Select = $(this.Name).parentNode.getElementsByTagName("select");
var self = this,_f = true;
var _FirstOption = [],_FirstLength = this.FirstOption.length;
if(this.FirstOption.length == 0)_f = false;
for(var i = 0;i < _Select.length; i++){
if(_f){
if(i >= _FirstLength)
_FirstOption = this.FirstOption[0];
else
_FirstOption = this.FirstOption[i];
_Select[i].options[0].text = _FirstOption[0];
_Select[i].options[0].value = _FirstOption[1];
}
if(i == _Select.length - 1)
_Select[i].setAttribute("onchange",function(){
var __Select = this.parentNode.getElementsByTagName("select");
$(self.Name).value = __Select[__Select.length - 1].value;
if(self.FirstOption.length != 0 && this.selectedIndex == 0)
if(_Select.length > 1)
$(self.Name).value = __Select[__Select.length - 2].value;
self.Fun(this);
});
else
_Select[i].setAttribute("onchange",function(){
self._RemoveSelect(this);
self._SelectNode(self.Source,this.value);
var __Select = this.parentNode.getElementsByTagName("select");
if(self.SelectFirst){
$(self.Name).value = __Select[__Select.length - 1].value;
}else
$(self.Name).value = __Select[__Select.length - 1].options[1].value;
if(self.FirstOption.length != 0 && this.selectedIndex == 0)
if(_Select.length > 1)
$(self.Name).value = __Select[__Select.length - 2].value;
self.Fun(this);
});
}
}
this._SelectNode = function(node,s){
for(var i = 0;i < node.childNodes.length; i++)
if(node.childNodes[i].getAttribute("Id") == s)
this.CreateSelect(node.childNodes[i]);
else
if(node.childNodes[i].hasChildNodes)this._SelectNode(node.childNodes[i],s);
}
this._RemoveSelect = function(o){
var _Select = $(this.Name).parentNode.getElementsByTagName("select");
var _f = false;
for(var i = 0;i < _Select.length; i++){
if(_Select[i] == o){_f = true;continue;}
if(_f){_Select[i].parentNode.removeChild(_Select[i]);i--;}
}
}
}
JavaScript技術:javascript 框架小結 個人工作經驗,轉載需保留來源!
鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。