轉載一些js 估計自己以後用的到
來源:互聯網
上載者:User
//仿VBS的trim函數,去除兩邊空格
function trim(str) {
return (str + '').replace(/(\s+)$/g, '').replace(/\s+/g, '');
}
//JS版的HTMLEncode,常用於轉換提交的HTML代碼
function HTMLEncode(text){
if(test=="")return("");
text = text.replace(/&/ig, "&"); // &
text = text.replace(/>/ig, ">"); // <
text = text.replace(/'/ig, "'"); // >
text = text.replace(/</ig, "<"); // '
text = text.replace(/"/ig, """); // "
text = text.replace(/\t/ig," "); //Tab
text = text.replace(/\r/ig,""); // 斷行符號
text = text.replace(/\n\n/ig,"<p>"); // 換行
text = text.replace(/\n/ig,"<br/>"); // 換行
text = text.replace(/\x20/ig," "); // 空格
return text ;
}
//仿ASP裡的include,引用載入其它javascript檔案
$js_path = "/js/";
function js_include($script) {
var script = document.createElement('script');
script.src = $js_path + $script;
script.type = 'text/javascript';
var head = document.getElementsByTagName('head').item(0);
head.appendChild(script);
}
//Example: js_include("prototype.js");