//删除html内容 jquery.removehtml = function (s) { return (s) ? jquery("
").append(s).text() : ""; } //调用:$.removehtml(str) //时间格式化 date.prototype.format = function (format) { /* * 使用例子:format="yyyy-mm-dd hh:mm:ss"; */ var o = { "m+": this.getmonth() + 1, // month "d+": this.getdate(), // day "h+": this.gethours(), // hour "m+": this.getminutes(), // minute "s+": this.getseconds(), // second "q+": math.floor((this.getmonth() + 3) / 3), // quarter "s": this.getmilliseconds() // millisecond } if (/(y+)/.test(format)) { format = format.replace(regexp.$1, (this.getfullyear() + "").substr(4 - regexp.$1.length)); } for (var k in o) { if (new regexp("(" + k + ")").test(format)) { format = format.replace(regexp.$1, regexp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length)); } } return format; } //调用:var time = new date(str.replace("-", "/")); //var b = 24 * 60; //分钟数 //time.setminutes(time.getminutes() + b, time.getseconds(), -1); //time.format("yyyy-mm-dd"); //添加收藏 function addfavorite(surl, stitle) { try { window.external.addfavorite(surl, stitle); } catch (e) { try { window.sidebar.addpanel(stitle, surl, ""); } catch (e) { alert("加入收藏失败,请使用ctrl+d进行添加"); } } } //获取当前url参数 function getquerystring(name) { var reg = new regexp("(^|&)" + name + "=([^&]*)(&|$)"); var r = window.location.search.substr(1).match(reg); if (r != null) return decodeuri(r[2]); return null; } //删除html后 截取字符串添加。。。 jquery.substr = function (con, len) { return $.removehtml(con).length > len ? $.removehtml(con).substr(0, len) + "..." : $.removehtml(con); } string.prototype.trim = function () { return this.replace(/(^\s*)|(\s*$)/g, ''); }; //去除字符串尾部空格或指定字符 string.prototype.trimend = function(c) { if(c==null||c=="") { var str= this; var rg = /\s/; var i = str.length; while (rg.test(str.charat(--i))); return str.slice(0, i + 1); } else { var str= this; var rg = new regexp(c); var i = str.length; while (rg.test(str.charat(--i))); return str.slice(0, i + 1); } } //去除字符串头部空格或指定字符 string.prototype.trimstart = function(c) { if(c==null||c=="") { var str= this.replace(/^\s*/g, ''); return str; } else { var rg=new regexp("^"+c+"*"); var str= this.replace(rg, ''); return str; } } //字符串正则表达式验证 string.prototype.regval = function(strreg) { var reg = new regexp(strreg); if (!reg.test(this)) { return false; } else { return true; } }; // string转化为number string.prototype.toint = function () { return isnan(parseint(this)) ? this.tostring() : parseint(this); }; //格式化字符串 string.format = function () { if (arguments.length == 0) { return ''; } if (arguments.length == 1) { return arguments[0]; } var reg = /{(\d+)?}/g; var args = arguments; var result = arguments[0].replace(reg, function ($0, $1) { return args[parseint($1) + 1]; }); return result; }; string.format2 = function (src) { if (arguments.length == 0) return null; var args = array.prototype.slice.call(arguments, 1); return src.replace(/\{(\d+)\}/g, function (m, i) { return args[i]; }); }; //var str = '这是一个测试的字符串:{0} {1}'.format3('hello', 'world') string.prototype.format3 = function (args) { var result = this; if (arguments.length > 0) { if (arguments.length == 1 && typeof (args) == "object") { for (var key in args) { if (args[key] != undefined) { var reg = new regexp("({" + key + "})", "g"); result = result.replace(reg, args[key]); } } } else { for (var i = 0; i < arguments.length; i++) { if (arguments[i] != undefined) { var reg = new regexp("({)" + i + "(})", "g"); result = result.replace(reg, arguments[i]); } } } } return result; } //容量单位换算 输入b单位 function bytestosize(bytes) { if (bytes === 0) return '0 b'; var k = 1024; // or 1024 sizes = ['b', 'kb', 'mb', 'gb', 'tb', 'pb', 'eb', 'zb', 'yb']; var i = math.floor(math.log(bytes) / math.log(k)); return (bytes / math.pow(k, i)).toprecision(3) + ' ' + sizes[i]; } //生成指定位数的随机码 function generaterandcode(n) { var chars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']; var res = ""; for (var i = 0; i < n ; i++) { var id = math.ceil(math.random() * 35); res += chars[id]; } return res; } $("a.post").click(function () { e.stoppropagation(); e.preventdefault(); var href = this.href; var parts = href.split('?'); var url = parts[0]; var params = parts[1].split('&'); var pp = ''; //for (var i = 0, n = params.length; i < n; i++) { // pp = params[i].split('='); // inputs += ''; //} //$("body").append('
'); //$("#poster").submit(); var jform = $(''); jform.attr('action', url); jform.attr('method', 'post'); for (var i = 0, n = params.length; i < n; i++) { pp = params[i].split('='); var jinput = $(""); jinput.attr('name', pp[0]); jinput.attr('value', pp[1]); jform.append(jinput); } document.write(jform); jform.submit(); });