最近对脚本有点感兴趣了..自己试着搞了个小东西出来..
<
HTA:APPLICATION
BORDER
="dialog"
INNERBORDER
="no"
BORDERSTYLE
="normal"
CAPTION
="yes"
MAXIMIZEBUTTON
="no"
MINIMIZEBUTTON
="yes"
SHOWINTASKBAR
="yes"
SINGLEINSTANCE
="no"
SYSMENU
="yes"
SCROLL
="no"
>
<
head
>
<
meta
http-equiv
=Content-Type
content
="text/html; charset=gb2312"
>
<
title
>
HTML 与 JS 代码互转 - Sea
</
title
>
![](https://i-blog.csdnimg.cn/blog_migrate/a41954a27d6ad96fa2c2cf816e677448.gif)
<
style
>
...
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
body{...}{background-color:menu;margin:0;font-size:12px;}
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
#head{...}{border:1px solid #777;padding:5px 10px;margin:2px;text-align:right;}
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
#oper{...}{text-align:center;display:inline;width:80%;}
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
#convert{...}{text-align:center;margin:5px;}
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
#oSource{...}{width:460px;height:200px;}
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
#oResult{...}{width:460px;height:200px;background:menu;}
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
#foot{...}{padding:5px 10px;margin:2px 20px;text-align:right;}
</
style
>
![](https://i-blog.csdnimg.cn/blog_migrate/a41954a27d6ad96fa2c2cf816e677448.gif)
<
SCRIPT
FOR
="window"
EVENT
="onload"
>
...
initialize();
</
SCRIPT
>
![](https://i-blog.csdnimg.cn/blog_migrate/a41954a27d6ad96fa2c2cf816e677448.gif)
<
script
>
...
// Event handler for window.onload()
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
function initialize() ...{
initWindow();
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
// Applies initial state settings for the application
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
function initWindow() ...{
setWindowSize(500, 540);
window.moveTo(100,50);
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
// Resizes the current window
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
function setWindowSize(width, height)...{
window.resizeTo(width, height);
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
// Opens a new window
function popWindow(url, name)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
// New window will be used to popup window if we haven't opened a readme before;
// Otherwise the same window will open again, only toolbar visible, resizable
var wndPopup = window.open(url,name,"");
// Bring new window to foreground
wndPopup.focus();
}
function doConvert()
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
var ConvertResult;
var v=oSource.value;
if (ConvertType1.checked) ConvertResult=html2js(v); else ConvertResult=js2html(v);
oResult.value=ConvertResult;
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
function html2js(paraV)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
return "document.writeln(""+paraV.replace(///g,"//").replace(///g,"//").replace(/'/g,"/'").replace(/"/g,"/"").split(' ').join(""); document.writeln("")+"")";
}
function js2html(paraV)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
return paraV.replace(/document.writeln("/g,"").replace(/");/g,"").replace(//"/g,""").replace(//'/g,""").replace(g,"/").replace(g,"/");
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
function doShift(v)
{
doConvert();
}
</script>
</head>
<body>
<div id="head">
<div id="oper">
<label><input type=radio value="html2js" name="c" id="ConvertType1" οnclick="doShift()" checked>HTMLtoJS</label>
<label><input type=radio value="js2html" name="c" id="ConvertType2" οnclick="doShift()">JStoHTML</label>
</div>
<input type=button value=" 关闭 " οnclick="self.close()" name="close" /></div>
<div id="convert">
源内容:
<textarea id="oSource" onpropertychange="doConvert()"></textarea>
<br/><br/>
转换结果:
<textarea id="oResult" title="双击复制" οndblclick='this.select();oResult.createTextRange().execCommand("Copy")'></textarea>
</div>
<div id="foot"><a href="http://blog.csdn.net/sea0x/">Sea</a> test... </div>
</body>
</HTA>