1.很多的网站都有一个html执行功能,其实实现起来非常简单:
![ContractedBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
<script language="javascript" type="text/javascript">
function runCode()
{
var code=document.getElementById("testarea").value;
if(code=="")
{
window.alert("代码框不能为空");
return;
}
else
{
var newin=window.open('','','');
newin.opener=null;
newin.document.write(code);
newin.document.close();
}
}
</script>
<textarea id="testarea" rows="5" cols="60"/>
<input type="button" value="确定" onclick="runCode();" />
2.在IE上实现复制到剪贴板的功能(只适应于IE)
![ContractedBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
<script language="javascript" type="text/javascript">
function runCode()
{
if(document.all)
{
otextRange=document.getElementById("testarea").createTextRange();
otextRange.execCommand("Copy");
window.alert("数据已复制到剪贴板");
}
}
</script>
<textarea id="testarea" rows="5" cols="60"></textarea>
<input type="button" value="确定" onclick="runCode();" />
3.Javascript函数execCommand详解
详见:http://www.blueidea.com/tech/web/2003/1242.asp,如:
winname.document.execCommand('saveas','','Code.htm'); ----保存代码
4.javascript更改元素的透明度:document.getElementById("eleName").filters.alpha.opacity=40;