关闭

(代码生成)JS写的代码生成器-编码也可以这么爽..

标签: functioninputbuttonjavascripttabledate
2106人阅读 评论(0) 收藏 举报
分类:

以下代码保存为HTML格式即可.
敬告:引用请注明出处

<script language = "javascript">
/*
Autor:Kangco
Date:2007/09/27
*/
function OutFile()
{
var text = "sdfsd";
response.setContentType("application/x-msdownload");
response.setHeader("Content-Disposition",
"attachment;" + " filename="+pid+".html");
response.getOutputStream().write(text.getBytes());
response.getOutputStream().flush();
}

function SaveAsOk()
{
 document.execCommand("saveAs");
}

function WriteFile()
{
  var   fso   =   new   ActiveXObject("Scripting.FileSystemObject");  
  var   a   =   fso.CreateTextFile("c://testfile.txt",   true);  
  a.WriteLine("This   is   a   test.");  
  a.Close();  
  alert("我已经在你的C盘根目录下生成了一个testfile.txt的文件!");  
}

function Split_rn()
{
//alert(split);
//substring("asdfs")
alert(document.getElementById("A005").value);
alert(document.getElementById("A005").value.split("/r/n")[0]);
alert(document.getElementById("A005").value.split("/r/n")[1]);
}

function docWrite_rn()
{
//alert(split);
//substring("asdfs")
var o_OK_value = document.getElementById("A005").value;
document.write("sdf");
document.write("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+o_OK_value.split("/r/n")[0]+ "<br>");
document.write(o_OK_value.split("/r/n")[1]+ "<br>");
}

function JS_1()
{
 var o_split = document.getElementById("A005").value.split("/r/n");
 for (var i = 0; i < o_split.length;i++)
 {
  document.write("document.getElementById(/""+o_split[i]+"/").style.display=/"none/";");
  document.write("<br>");
 }
}

function JS_2()
{
 
 var o_split = document.getElementById("A005").value.split("/r/n");
 var o_A006_value = ReplaceAll(ReplaceAll(document.getElementById("A006").value,"/r/n","<br>")," ","&nbsp;");
 document.write("<a href='javascript:history.go(-1);'>返回</a><br>");
 for (var i = 0; i < o_split.length;i++)
 {
  //document.write("document.getElementById(/""+o_split[i]+"/").style.display=/"none/";");
  //document.write("<br>");
  //alert(o_split[i].split(",").length);
  var out_value = o_A006_value;//每次進行循環替換前均初始化為界面設定值
  
  //智能判斷是否產生,以免產生垃圾代碼
  var b_OK = "N";
  for(var j = 0; j < o_split[i].split(",").length;j++)
  {
   if(o_split[i].split(",")[j].trim() != ""&&o_split[i].split(",")[j].trim() != null)
   {
    b_OK = "Y";//其中一個不為空,即為有效產出
   }
  }
  //alert(b_OK );
  if(b_OK == "Y")
  {
   for(var j = 0; j < o_split[i].split(",").length;j++)
   {
    out_value = ReplaceAll(out_value,"{"+j+"}",o_split[i].split(",")[j].trim());
   }

   document.write("<div style = 'font-size:12px'>"+out_value+"</div>");
  }
 }

 
}
//Replace進一步擴展
function ReplaceAll(strOrg,strFind,strReplace)
{//eg:ReplaceAll(o_txtUNID_PRICE.value,",","")
    var index = 0;
    while(strOrg.indexOf(strFind,index) != -1)
    {
        strOrg = strOrg.replace(strFind,strReplace);
        index = strOrg.indexOf(strFind,index);
    }
    return strOrg
}

function JS_3()
{
 var o_AutoCode = document.getElementById("AutoCode");
 var o_TempCode = document.getElementById("TempCode");
 if(o_AutoCode.style.display == "")
 {
  o_AutoCode.style.display = "none";
  o_TempCode.style.display = "";
  document.getElementById("temp_eg").value = "產出設定";
  document.getElementById("006").disabled = true;
 }
 else
 {
  o_AutoCode.style.display = "";
  o_TempCode.style.display = "none";
  document.getElementById("temp_eg").value = "示例模板";
  document.getElementById("006").disabled = false;
 }
}
String.prototype.trim = function()
{
 var i,j;
 var str = this.replace(/(^/s*)|(/s*$)/g,'');
    if(str == "") return "";
    for(i=0;i<str.length;i++)
    if(str.charAt(i) != ' ') break;
    if(i >= str.length) return "";
    for(j=str.length-1;j>=0;j--)
    if(str.charAt(j) != ' ') break;
    return str.substring(i,j+1).replace(/(^/s*)|(/s*$)/g,''); 
}

</script>


<input id="001" type="hidden" value="button" onclick="OutFile()"/>
<input id="002" type="hidden" value="button" onclick="SaveAsOk()"/>
<input id="003" type="hidden" value="WriteFile" onclick="WriteFile()"/>

<input id="004" type="hidden" value="Split" onclick="Split_rn()"/>
<input id="005" type="hidden" value="docWrite" onclick="docWrite_rn()"/>
<br>
<input id="006"  type="button" value="產生代碼" onclick="JS_2()"/>
<input id="temp_eg"  type="button" value="示例模板" onclick="JS_3()"/>
<br>
<table id = "AutoCode">
<tr>
<td>參數</td>
<td>
<textarea id="A005" type="text" style="width:600px;height:200px;">
txtCONVERT_DATE,折舊日期</textarea>
</td>
</tr>
<tr>
<td>
模板
</td>
<td>
<textarea id="A006" type="text" style="width:800px;height:200px;">
document.getElementById("img{0}").style.display="none";//{1}
var o_{0}=document.getElementById("{0}");
if(o_{0}.value.trim()=='')
{//{1}
        document.getElementById("img{0}").style.display="";
        ShowError('00018','{1}');
        o_{0}.focus();
        return false;
}
</textarea>
</td>
</tr>
</table>
<table id = "TempCode" style = "display:none;font-size:12px;width:100%" cellspacing="0" cellpadding="0" border = "1">
<tr>
<td nowrap>
[JS]設定圖像顯示為none
</td>
<td>
<textarea type="text" style="width:100%">
document.getElementById("img{0}").style.display="none";//{1}</textarea>
</td>
</tr>
<tr>
<td>
[JS]IsMust檢測
</td>
<td>
<textarea type="text" style="width:100%;height:200px">
var o_{0}=document.getElementById("txtDEPOSIT_ID");
if(o_{0}.value.trim()=='')
{//{1}
        document.getElementById("img{0}").style.display="";
        ShowError('00018','{1}');
        o_{0}.focus();
        return false;
}</textarea>
</td>
</tr>

</table>
 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:317915次
    • 积分:4288
    • 等级:
    • 排名:第7300名
    • 原创:120篇
    • 转载:77篇
    • 译文:0篇
    • 评论:31条
    最新评论