常用的JavaScript操作II

//读取指定文件目录的xml文件,返回字符串 var readXML = function($xmlFile){ //读取用户的安装目录 var fos = external.createObject('FileInputStream'); var str = ''; if (fos.open($xmlFile)) { str = fos.read(); fos.close(); } return str; }; //把数据写入到指定的文件中 var writeXML = function(filename,data){ //读取用户的安装目录 var fos = external.createObject('FileOutputStream'); if (fos.open(filename)) { //alert("haha"); fos.write(data); fos.close(); } }; /** * 把xml形式的string转化为xml的DOM格式 * 例如:var userXML = $.createXMLDocument(userXmlString); //typeof(userXmlString) = string; */ jQuery.createXMLDocument = function(string) { var browserName = navigator.appName; var doc; if (browserName == 'Microsoft Internet Explorer') { doc = new ActiveXObject('Microsoft.XMLDOM'); doc.async = 'false'; doc.loadXML(string); } else { doc = (new DOMParser()).parseFromString(string, 'text/xml'); } return doc; }; /** * 把DOM格式的对象转化为字符串 * Converts XML node(s) to string using web-browser features. * Similar to .html() with HTML nodes * This method is READ-ONLY. * * @param all set to TRUE (1,"all",etc.) process all elements, * otherwise process content of the first matched element * * @return string obtained from XML node(s) */ jQuery.fn.xml = function(all) { //result to return var s = ""; //Anything to process ? if( this.length ) //"object" with nodes to convert to string ( ( ( typeof all != 'undefined' ) && all ) ? //all the nodes this : //content of the first matched element jQuery(this[0]).contents() ) //convert node(s) to string .each(function(){ s += window.ActiveXObject ?//== IE browser ? //for IE this.xml : //for other browsers (new XMLSerializer()).serializeToString(this) ; }); return s; }; //">"用2表示 ">="用1表示 "<"用-2表示 "<="用-1表示 String.prototype.symbolTrans = function(str) { var s; switch(str){ case '2': s = ">"; break; case '1': s = ">="; break; case '-1': s = "<="; break; default: s = "<"; break; } return s; } //无提示的关闭页面 function Close() { var ua = navigator.userAgent; var ie = navigator.appName == "Microsoft Internet Explorer" ? true : false; if(ie) { var IEversion = parseFloat(ua.substring(ua.indexOf("MSIE ") + 5, ua.indexOf(";", ua.indexOf("MSIE ")))); if(IEversion < 5.5) { var str = '<object id=noTipClose classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">' str += '<param name="Command" value="Close"></object>'; document.body.insertAdjacentHTML("beforeEnd", str); document.all.noTipClose.Click(); } else { window.opener = null; window.close(); } } } //对于网站的url地址解析,可以使用已有的jquery插件,jget,非常方便的解析出网址的元素。 var url = $.jget['var1']; $.debug(url); jQuery.extend({ //start the jget Object jget : {}, //get the url, //用户可以在这里自行定义字符串 url : unescape(window.location.href).replace(/^[^/?]+/??/,''), //get the queryString parseQuery : function(query) { var Params = {}, if (!query) { return Params; //return empty Object } var Pairs = query.split(/[;&]/); for (var i = 0; i < Pairs.length; i++) { var KeyVal = Pairs[i].split('='); if (!KeyVal || KeyVal.length != 2) { continue; } var key = unescape( KeyVal[0] ); var value = unescape( KeyVal[1] ); val = val.replace(//+/g, ''); Params[key] = val; } return Params; }, //Make the jget Object available to jQuery.extend getQueryString : function() { this.jget = this.parseQuery(this.url); } //debugging debug: function(message) { if (!$.browser.msie) { console.info(message); } else if ($.browser.safari) { window.console.log(message); } else { alert(message); } } }); //start the plugin $.getQueryString(); 这个js文件是一个公共文件:

你可能感兴趣的:(常用的JavaScript操作II)