日期:2014-05-16 浏览次数:20481 次
更新内容:
1.新增可以自定义提示参数名
2.提交等事件可以只绑定一次
3.整合一些常用的验证到里面去
var urlHelp = {}; // 跳转页面 urlHelp.GoUrl = function(url, addbackurl) { if (addbackurl != true) addbackurl = false; if (addbackurl == true) { var backurl = urlHelp.request('backurl'); if (backurl != null && backurl != undefined && backurl != "") { url = urlHelp.setRequest(url, "backurl", backurl); } } location.replace(url); } //得到当前页面URL urlHelp.getPageUrl = function() { var oldurl = location.href; var url = oldurl.substring(oldurl.length - 1, oldurl.length); while (url == "#") { oldurl = oldurl.substring(0, oldurl.length - 1); url = oldurl.substring(oldurl.length - 1, oldurl.length); } oldurl = urlHelp.setRequest(oldurl, "mathrandom", Math.random()); return oldurl; if (oldurl.indexOf('?') != -1) { var index = oldurl.lastIndexOf("&", oldurl.length); if (index != -1) { var a = oldurl.substring(index + 1, oldurl.length); if (!isNaN(a)) { oldurl = oldurl.substring(0, index) } } oldurl = oldurl + "&" + Math.random(); } else { oldurl = oldurl + "?" + Math.random(); } return oldurl; } //对内容进行编码 urlHelp.getEncodeURI = function(content) { content = encodeURIComponent(content); content = urlHelp.MyReplace(content, "#", "%23"); return content; } // 对内容进行替换 urlHelp.MyReplace = function(content, value1, value2) { var reg = new RegExp(value1, "g"); content = content.replace(reg, value2); return content; } // 获取URL参数 urlHelp.request = function(paras) { var url = location.href; var paraString = url.substring(url.indexOf("?") + 1, url.length).split("&"); var paraObj = {} for (i = 0; j = paraString[i]; i++) { paraObj[j.substring(0, j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf("=") + 1, j.length); } var returnValue = paraObj[paras.toLowerCase()]; if (typeof (returnValue) == "undefined") { return ""; } else { return urlHelp.MyReplace(returnValue, '#', ''); } } urlHelp.setRequest = function(url, par, par_value) { var pattern = par + '=([^&]*)'; var replaceText = par + '=' + par_value; if (url.match(pattern)) { var tmp = '/\\' + par + '=[^&]*/'; tmp = url.replace(eval(tmp), replaceText); return (tmp); } else { if (url.match('[\?]')) { return url + '&' + replaceText; } else { return url + '?' + replaceText; } } return url; } // JavaScript Document if (typeof (HTMLElement) != "undefined") { HTMLElement.prototype.insertAdjacentElement = function(where, parsedNode) { switch (where) { case "beforeBegin": this.parentNode.insertBefore(parsedNode, this); break; case "afterBegin": this.insertBefore(parsedNode, this.firstChild); break; case "beforeEnd": this.appendChild(parsedNode); break; case "afterEnd": if (this.nextSibling) this.parentNode.insertBefore(parsedNode, this.nextSibling); else this.parentNode.appendChild(parsedNode); break; } } HTMLElement.prototype.insertAdjacentHTML = function(where, htmlStr) { var r = this.ownerDocument.createRange(); r.setStartBefore(this); var parsedHTML = r.createContextualF