网页上运行代码和复制代码

 

代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
<script>
function runEx(cod1)  {
     cod
=document.getElementById(cod1)
      
var code=cod.value;
      
if (code!=""){
          
var newwin=window.open('','','');  
          newwin.opener 
= null 
          newwin.document.write(code);  
          newwin.document.close();
    }
}

function doCopy(ID) { 
    
if (document.all){
         textRange 
= document.getElementById(ID).createTextRange(); 
         textRange.execCommand(
"Copy"); 
    }
    
else{
         alert(
"此功能只能在IE上有效")
    }
}
</script>
</head>
<body>

<textarea rows="10" cols="30" id='code' ></textarea>
<input type="button" onclick='runEx("code")' value='运行代码'/>
<input type="button" onclick='doCopy("code")' value='复制代码'/>

</body>
</html>

 

 

posted on 2010-03-24 17:12  优雅小猪  阅读(491)  评论(0编辑  收藏  举报

导航