html->javascript->jsp(out.println())

发表于:2007-06-21来源:作者:点击数: 标签:
%@LANGUAGE= VB SCRIPT CODEPAGE=936% html head meta http-equiv=Content-Type content=text/html; charset=gb2312 titlehtml转js转jsp(或servlet)/title style type=text/css !-- body { font-size: 12px; text-align: center; margin: 0px; border: none;

   


<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>html转js转jsp(或servlet)</title>
<style type="text/css">
<!--
body {
font-size: 12px;
text-align: center;
margin: 0px;
border: none;
background-color: #CCCCCC;
}
-->
</style>
</head>

<body scroll=no>
<script>
function html2js(codestr){
var codes=codestr.split("\n");
var jscode="";
var tcode="";
for(var a=0;a<codes.length;a++){
if(codes[a].replace(/\s+/,"")!=""){
tcode="";
tcode+=codes[a].replace(/\"/ig,"\\\\\\\"").replace(/(\s+)</ig,"<").replace(/\//ig,"\/");
tcode="out.println(\"document.write(\\\""+tcode+"\\\");\");\n";
jscode+=tcode.replace(/\r/ig,"");
//alert(jscode);
}
}
jscode="out.println(\"<script language=\\\"javascript\\\">\");\n"+jscode+"out.println(\"<\/script>\");";
return jscode;
}
function runcode(){
var mywin=window.open("","测试窗口","")
mywin.document.open();
mywin.document.write(jscode.value);
mywin.document.close();
}
</script>
<textarea name="htmlcode" style="width:100%" rows="15" id="htmlcode"></textarea>
<input type="button" name="Submit" value=" 转 换 " onClick="jscode.value=html2js(htmlcode.value)">
<input type="button" name="Submit2" value=" 测 试 " onClick="runcode()">
<br>
<textarea name="jscode" style="width:100%" rows="15" id="jscode"></textarea>
<br>
</body>
</html>

原文转自:http://www.ltesting.net