首页 > 代码库 > 常用JS
常用JS
$_format = function (source, params) { if (arguments.length == 1) return function () { var args = $.makeArray(arguments); args.unshift(source); return $.validator.format.apply(this, args); }; if (arguments.length > 2 && params.constructor != Array) { params = $.makeArray(arguments).slice(1); } if (params.constructor != Array) { params = [params]; } $.each(params, function (i, n) { source = source.replace(new RegExp("\\{" + i + "\\}", "g"), isNull(n) ? ‘‘ : n); }); return source;};
//获取URL参数function GetQueryString(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); var r = window.location.search.substr(1).match(reg); if (r != null) return r[2]; return null;}
function FilterPasteText(str) { if (!str) { return ‘‘; } //str = str.replace(/[\n\r]/ig, ""); //remove html body form str = str.replace(/<\/?(html|body|form)(?=[\s\/>])[^>]*>/ig, ""); //remove doctype str = str.replace(/<(!DOCTYPE)([^<>])*?>/ig, ""); //remove xml tags str = str.replace(/<(\/?(\?xml(:\w+)?|xml|\w+:\w+)(?=[\s\/>]))[^>]*>/gi, ""); //remove head str = str.replace(/<head[^>]*>[\s\S]*?<\/head>/ig, ""); //remove <xxx /> str = str.replace(/<(script|style|link|title|meta|textarea|option|select|iframe|hr)[\s\S]*?\/>/ig, ""); //remove empty span str = str.replace(/<span[^>]*?><\/span>/ig, ""); //remove <xxx>...</xxx> str = str.replace(/<(head|script|style|textarea|button|select|option|iframe)[^>]*?>[\s\S]*?<\/\1>/ig, ""); str = str.replace(/<(head|script|style|textarea|button|select|option|iframe)[^>]*?>/ig, ""); //remove table and <a> tag, <img> tag,<input> tag (this can help filter unclosed tag) str = str.replace(/<\/?(a|table|tr|td|tbody|thead|th|img|input|iframe|div)[^>]*>/ig, ""); //remove bad attributes do { len = str.length; str = str.replace(/(<[a-z][^>]*\s)(?:id|name|language|type|class|on\w+|\w+:\w+)=(?:"[^"]*"|\w+)\s?/gi, "$1"); str = str.replace(/[<>]/gi, ""); } while (len != str.length); return str;}
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。