Javascript

    技术2022-05-20  37

    <body bgColor=white style="font-size:9pt">

    <style>.btn{    border-style:solid;    border-width:1px;    border-left-color:#5194F4;    border-top-color:#5194F4;    border-right-color:#215494;    border-bottom-color:#215494;    background: #daeaff;     color: #002200;    height: 21px;}.txt{    background-color: #FFFFFF;    border-left-width:1px;    border-left-style:solid;    border-left-color:#3F6D99;    border-top-width:1px;    border-top-style:solid;    border-top-color:#3F6D99;

        border-right-width:1px;    border-right-style:solid;    border-right-color:#BBBBDD;    border-bottom-width:1px;    border-bottom-style:solid;    border-bottom-color:#BBBBDD;  font-size: 12px; color: black;    height:20px;}.txtArea{    background-color: #FFFFFF;    border-left-width:1px;    border-left-style:solid;    border-left-color:#3F6D99;    border-top-width:1px;    border-top-style:solid;    border-top-color:#3F6D99;

        border-right-width:1px;    border-right-style:solid;    border-right-color:#BBBBDD;    border-bottom-width:1px;    border-bottom-style:solid;    border-bottom-color:#BBBBDD;  font-size: 12px; color: black;}.page{   width:470;padding:5px;}</style><textarea class="txtArea" cols=130 rows=25 id="txt1"></textarea><br><br style="line-height:7px"><input class="btn" type="button" value="格式化SQL代码" οnclick="btnRptLT(this)"><input class="btn" type="button" value="格式化VB代码" οnclick="btnRptLT(this)"><input class="btn" type="button" value="格式化C#代码" οnclick="btnRptLT(this)"><input class="btn" type="button" value="格式化JS代码" οnclick="btnRptLT(this)"><br><br style="line-height:7px"><input class="btn" type="button" value="替换<" οnclick="btnRptLT(this)"><input class="btn" type="button" value="替换为全角空格" οnclick="btnRptEpt(this)"> <input class="btn" type="button" value="替换连续换行符" οnclick="btnRptCR(this)"> <input class="btn" type="button" value="添加Pre24px" οnclick="btnAddPre(this)"> <input class="btn" type="button" value="添加PreDivCust" οnclick="btnAddDiv(this)"> <input class="btn" type="button" value="添加行高" οnclick="btnRowHeight(this)"> <input class="btn" type="button" value="替换p与br" οnclick="btnPBr(this)"> <input class="btn" type="button" value=" 显 示 " οnclick="btnShow(this)"><br><br style="line-height:7px"> 源文本:<input type="txt" class="txt" id="x1">  替换文本:<input id="x2" type="txt" class="txt">  <input class="btn" type="button" value="普通替换" οnclick="btnRptCmm(me)" language="vbscript">  <input class="btn" type="button" value="转义替换" οnclick="btnRptZhanyi(me)" language="vbscript">  <input class="btn" type="button" value="正则替换" οnclick="btnRptReg(this)">  <input class="btn" type="button" value="非连续替换" οnclick="btnRptNoLianXu(this)"><br><br style="line-height:7px"> 字符串:<input type="txt" class="txt" id="x3">  <input class="btn" type="button" value="查看编码" οnclick="btnShowCode(this)">  <span id="span1"></span><br><br style="line-height:7px"> <input class="btn" type="button" value="缩进半角" οnclick="btnIndent1(this)"> <input class="btn" type="button" value="缩进全角" οnclick="btnIndent2(this)"> <input class="btn" type="button" value="左移半角" οnclick="btnLeft1(this)"> <input class="btn" type="button" value="左移全角" οnclick="btnLeft2(this)"> <input class="btn" type="button" value="格式化半角字符" οnclick="btnFormatAscii(this)">  <input type="txt" class="txt" id="txtSave" value="temp.html">  <input class="btn" type="button" value=" 保 存 " οnclick="SaveFile(this)"><br><br style="line-height:7px"> 服务器:<input type="txt" class="txt" id="txtSrv" style="width:80"> 用户:<input type="txt" class="txt" id="txtUser" style="width:80" value="sa"> 密码:<input type="passowrd" class="txt" id="txtPwd" style="width:80">  <input class="btn" type="button" value=" 连  接 " οnclick=""> 数据库:<select class="txt" id="selDb" style="width:80"></select> 表:<select class="txt" id="selDb" style="width:80"></select>  <input class="btn" type="button" value="生成实体" οnclick=""><br><br style="line-height:7px"> <input class="btn" type="button" value="JS语法检查" οnclick="">  <input class="btn" type="button" value="格式化JS代码" οnclick="">  <input class="btn" type="button" value="格式C系列注释" οnclick="FormatCSComment(me)" language="vbscript">  <input class="btn" type="button" value="格式VB系列注释" οnclick="FormatVBComment(me)" language="vbscript">  <input class="btn" type="button" value="格式Sql系列注释" οnclick="FormatSqlComment(me)" language="vbscript">  <input class="btn" type="button" value="MVC各层参考" οnclick=""><br><br style="line-height:7px"> <fieldset class="page" οnclick="showHelp(this)">    <legend style="cursor:hand">版本历史+</legend>

    09-09-13 13:41 增加“转义替换”功能,转义字符包括/r/n/t等<br>

    </pre></fieldset><script language="javascript">var ta = document.getElementById("txt1");var mPreCtl = null; function InsertString(_src,_index,_insert){    var str1 = _src.substring(0,_index+1);    var str2 = _src.substring(_index+1);    return str1+_insert+str2; }function formatAscii(_str){//这里是对半角字符格式化,而不是对全角格式化,//不过不格式化回车换行符、空格、制表键这些空白字符   var formatBegin = '<b class=x>';   var f = '<b class=x">';   var formatEnd = '</b>';   var k = _str.replace(/([/x00-/xff ]{5,})/g, formatBegin + "$1" + formatEnd)   return k/*   var k = _str;   var formatting  = false;   for(var i=k.length-1;i>=0;i--){      var c = k.charCodeAt(i);      if(c<256){         if(!formatting){            if(c!=10&&c!=13&&c!=32){               k = InsertString(k,i,formatEnd);               formatting=true;            }         }         else{            if(i==0){               k = formatBegin+k;               formatting=false;            }         }      }      else{         if(formatting){            formatting=false;            k = InsertString(k,i,formatBegin);         }      }   }   return k;*/}function showHelp(x){   if(x.showthis){      x.showthis = false;      x.firstChild.innerText = "版本历史+";      x.style.color = "#000000";   }   else{      x.showthis = true;      x.firstChild.innerText = "版本历史-";       x.style.color = "#BB0000";   }}function btnPBr(x){   var v = ta.value;   v = v.replace(/[<]br[>]/g,"");   v = v.replace(/[<]p[>]/g,"/r/n");   v = v.replace(/[<][/]p[>]/g,"");   ta.value = v;   changeColor(x);}function btnFormatAscii(x){   v = ta.value;   ta.value = formatAscii(v);   changeColor(x)}

    function btnRowHeight(x){   var v = ta.value;   var sa = new Array();   var ssty = " style='line-height:24px'";   r = /([<][a-zA-Z0-9]+)/g   v = v.replace(r,"$1" + ssty);   v = v.replace(/[<]tr style=[']line-height:24px[']/g,"<tr");   v = v.replace(/[<]td style=[']line-height:24px[']/g,"<td");   v = v.replace(/[<]th style=[']line-height:24px[']/g,"<th");   var nBegin = -1;   var dt = new Date();   var time = dt.getTime();   var ss = "";   for(var i=0;i<v.length;i++){      var c = v.charAt(i);      if(c == "<"){         nBegin = i;      }      else if(c == ">"){         if(nBegin > -1){            var ssub  = v.substring(nBegin,i).toLowerCase();            var si = ssub.indexOf("style")            if(si != ssub.lastIndexOf("style")){               sa[sa.length] = nBegin + si;            }         }      }   }   for(var i=sa.length-1;i>=0;i--){      v = v.substring(0,sa[i]) + v.substring(sa[i] + ssty.length);   }   ta.value = v   changeColor(x);}

    function btnIndent1(x){   v = ta.value;   ta.value = "  " + v.replace(//r/n/g,"/r/n  ");   changeColor(x)}function btnIndent2(x){   v = ta.value;   ta.value = " " + v.replace(//r/n/g,"/r/n ");   changeColor(x)}function btnLeft1(x){   v = ta.value;   v = v.replace(//r/n  /g,"/r/n");   if(v.charCodeAt(0)==32) v = v.substring(1);   if(v.charCodeAt(0)==32) v = v.substring(1);   ta.value = v   changeColor(x)}function btnLeft2(x){   v = ta.value;   v = v.replace(//r/n /g,"/r/n");   if(v.charAt(0)==" ") v = v.substring(1);   ta.value = v   changeColor(x)}function btnRptLT(x){   v = ta.value;   ta.value = v.replace(/[<]/g,"<");      changeColor(x)}function btnRptEpt(x){   v = ta.value;   ta.value = v.replace(/  /g," ");   changeColor(x)}function btnRptCR(x){   v = ta.value;   ta.value = v.replace(//r/n/r/n/g,"/r/n");   changeColor(x)}function btnAddPre(x){   v = ta.value;   ta.value = "<pre style='font-size:14px;font-family:宋体;line-height:24px;'>" + v + "</pre>";   changeColor(x)}function btnAddDiv(x){   v = ta.value;   ta.value = "<pre style='font-size:11pt;font-family:宋体;line-height:24px;background:" +              "url(http://hiphotos.baidu.com/mkjxknioitvere/pic/item/6d33c72b2ac518125243c14d.jpg);position:relative;" +              "left:-10;top:-10;width:780px;padding-left:5px;padding-right:5px;'>" + v + "</pre>";   changeColor(x)}

    function btnShow(x){   var v = window.open();   v.document.write(ta.value);   changeColor(x)//   var dv = document.getElementById("div1");//   dv.innerHTML = "<br><br>" + ta.value;  }function btnRptReg(x){  t1 = document.getElementById("x1")  t2 = document.getElementById("x2")  eval("ta.value = ta.value.replace(/" + t1 + "/g," + t2 + ")");  changeColor(x)}function btnShowCode(x){  t1 = document.getElementById("x3");  var v = t1.value;  if(v.length > 0){     var ss = new Array(v.length);     for(var i=0;i<v.length;i++){        ss[i] = v.charCodeAt(i);     }     document.getElementById("span1").innerText = ss.join(";") + ";(" + v.length + ")";  }  changeColor(x)}function changeColor(x){  x.style.color = "#AA0000";  if(mPreCtl != null) mPreCtl.style.color = "#008888";  mPreCtl = x;}</script><script language="vbscript">function FormatSqlComment(x)   v = document.getElementById("txt1").value   ss = split(v,chr(13)+chr(10))   for i=0 to ubound(ss)      s = trim(ss(i))      if InStr(s,"--") = 1 then          ss(i) = "<font color=#006600>" + ss(i) + "</font>"      end if   next   sr = join(ss,chr(13)+chr(10))   sr = replace(sr,"</font>" + chr(13)+chr(10) + "<font color=#006600>",chr(13)+chr(10))   ta.value = sr   changeColor(x)end function

    function btnRptZhanyi(x)  v0 = document.getElementById("txt1").value ' 不能用 o = document.getElementById("txt1") : msgbox o.value  v1 = document.getElementById("x1").value  v2 = document.getElementById("x2").value  v1 = replace(v1,"/r/n",chr(13)+chr(10))  v1 = replace(v1,"/t",chr(9))  v2 = replace(v2,"/r/n",chr(13)+chr(10))  v2 = replace(v2,"/t",chr(9))  ss = replace(v0,v1,v2)  document.getElementById("txt1").value = ss  changeColor(x)end functionfunction FormatCSComment(x)   v = document.getElementById("txt1").value   ss = split(v,chr(13)+chr(10))   for i=0 to ubound(ss)      s = trim(ss(i))      if InStr(s,"//") = 1 then          ss(i) = "<font color=#006600>" + ss(i) + "</font>"      end if   next   sr = join(ss,chr(13)+chr(10))   sr = replace(sr,"</font>" + chr(13)+chr(10) + "<font color=#006600>",chr(13)+chr(10))   ta.value = sr   changeColor(x)end functionfunction FormatVBComment(x)   v = document.getElementById("txt1").value   ss = split(v,chr(13)+chr(10))   for i=0 to ubound(ss)      s = trim(ss(i))      if InStr(s,"'") = 1 then          ss(i) = "<font color=#006600>" + ss(i) + "</font>"      end if   next   sr = join(ss,chr(13)+chr(10))   sr = replace(sr,"</font>" + chr(13)+chr(10) + "<font color=#006600>",chr(13)+chr(10))   ta.value = sr   changeColor(x)end functionfunction btnRptCmm(x)  v0 = document.getElementById("txt1").value ' 不能用 o = document.getElementById("txt1") : v0 = o.value : msgbox v0  v1 = document.getElementById("x1").value  v2 = document.getElementById("x2").value  ss = replace(v0,v1,v2)  document.getElementById("txt1").value = ss  changeColor(x)end functionfunction btnRptNoLianXu(x)  v0 = document.getElementById("txt1").value  v1 = document.getElementById("x1").value  v2 = document.getElementById("x2").value  vv = "js_btnRptNoLianXu" & timer  s = replace(v0,v1+v1,vv)  msgbox s  s = replace(s,v1,v2)  msgbox s  s = replace(s,vv,v2+v2)  msgbox s  document.getElementById("txt1").value = s  msgbox s  changeColor(x)end function</script>

    <div style="font-size:9pt;" id="div1"></div>


    最新回复(0)