转载一些js 估计自己以后用的到

  • //仿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");   
  • posted @ 2008-04-29 16:03  雨中漫步的太阳  阅读(191)  评论(0编辑  收藏  举报