关闭

自编JS代码生成器V1.1版(更新后输出显示更便捷)

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

 

代码生成器V1.1版,最更新为2007/10/06
复制以下代码另存为 HTM格式即可:
 
<script language = "javascript">
/*
作者:关康球[Kangco]
时间:2007/09/27
程序功能:代码生成
参数:设定参数、设定模板
调用方法:参考示例模板、相关视频演示
 
开发记录:
2007/09/27 完成器件功能并进行相关测试与使用;
2007/09/28 对输出显示方式作调整;
2007/10/06 输出换行及空行的修整
*/
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;");
        var o_A006_value = document.getElementById("A006").value;
        //document.write("<a href='javascript:history.go(-1);'>返回</a><br>");
        var out_value_sum = "";
        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 );alert(out_value);
                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>");
                        if(out_value_sum == "")
                        {
                                out_value_sum = out_value;
                        }
                        else
                        {
                                out_value_sum = out_value_sum + "/r/n"+ out_value;
                        }
                       
                }
                document.getElementById("out001").value = out_value_sum;
        }
 
       
}
//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:150px;">
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>
<tr>
<td>
输出
</td>
<td>
<textarea type="text" style="width:100%;height:150px" id = "out001">
</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网站的观点或立场
    个人资料
    • 访问:312631次
    • 积分:4243
    • 等级:
    • 排名:第7178名
    • 原创:120篇
    • 转载:77篇
    • 译文:0篇
    • 评论:31条
    最新评论