Js与Html互转的一个hta的小工具

来源:互联网 发布:tcl电视网络电视看不了 编辑:程序博客网 时间:2024/06/06 10:53

最近对脚本有点感兴趣了..自己试着搞了个小东西出来..

 

<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>
<style>
body
{background-color:menu;margin:0;font-size:12px;}
#head
{border:1px solid #777;padding:5px 10px;margin:2px;text-align:right;}
#oper
{text-align:center;display:inline;width:80%;}
#convert
{text-align:center;margin:5px;}
#oSource
{width:460px;height:200px;}
#oResult
{width:460px;height:200px;background:menu;}
#foot
{padding:5px 10px;margin:2px 20px;text-align:right;}
</style>
<SCRIPT FOR="window" EVENT="onload">
initialize();
</SCRIPT>
<script>
// Event handler for window.onload()
function initialize()   {
    initWindow();
}


// Applies initial state settings for the application
function initWindow()   {
    setWindowSize(
500540);
    window.moveTo(
100,50);
}


// Resizes the current window
function setWindowSize(width, height){
    window.resizeTo(width, height);
}


// Opens a new window
function popWindow(url, name)
{
    
// 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()
{
  
var ConvertResult;
  
var v=oSource.value;
  
if (ConvertType1.checked) ConvertResult=html2js(v); else ConvertResult=js2html(v);
  oResult.value
=ConvertResult;
}


function html2js(paraV)
{
    
return "document.writeln(""+paraV.replace(///g,"//").replace(///g,"//").replace(/'/g,"/'").replace(/"/g,"/"").split(' ').join(""); document.writeln("")+"")";
}
 
 
function js2html(paraV)
{
    
return paraV.replace(/document.writeln("/g,"").replace(/");/g,"").replace(//"/g,""").replace(//'/g,""").replace(////g,"/").replace(////g,"/");
}

function doShift(v)
{
doConvert();

</script>
</head>
<body>
<div id="head">
<div id="oper">
<label><input type=radio value="html2js" name="c" id="ConvertType1" onclick="doShift()" checked>HTMLtoJS</label>
&nbsp;
<label><input type=radio value="js2html" name="c" id="ConvertType2" onclick="doShift()">JStoHTML</label>
</div>
<input type=button value=" 关闭 " onclick="self.close()" name="close" /></div>
<div id="convert">
源内容:
<textarea id="oSource" onpropertychange="doConvert()"></textarea>
<br/><br/>
转换结果:
<textarea id="oResult" title="双击复制" ondblclick=
'this.select();oResult.createTextRange().execCommand("Copy")'></textarea>
</div>
<div id="foot"><a href="http://blog.csdn.net/sea0x/">Sea</a> test... </div>
</body>
</HTA>
 

 

原创粉丝点击