最新消息:iOS编程开发交流群(6906921) ,Mac.Cocoa开发交流群(7758675) 欢迎iOS/macOS开发编程爱好及学习者加入!

在线运行HTML/JS代码预览html效果的实现

HTML 天狐 12419浏览 0评论

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>在线运行HTML/JS代码在线预览html效果</title>
<script type="text/javascript" language="javascript">
var is_ie=document.all;
//运行代码
function runcode(obj) {
 var winname=window.open('',"_blank",'');
 winname.document.open('text/html','replace');
 winname.opener=null;
 winname.document.write(obj.value);
 winname.document.close();
}
//复制代码
function copycode(obj) {
 if(is_ie && obj.style.display!='none') {
  var rng=document.body.createTextRange();
  rng.moveToElementText(obj);
  rng.scrollIntoView();
  rng.select();
  //or target=obj.createTextRange();
  rng.execCommand("Copy");
  rng.collapse(false);
 }
}
//另存代码
function savecode(obj) {
 var winname=window.open('','_blank','top=10000');
 winname.document.open('text/html','replace');
 winname.document.write(obj.value);
 winname.document.execCommand('saveas','','code.htm');
 winname.close();
}
//剪切代码
function cutcode(obj) {
 if(document.all) {
  textRange=obj.createTextRange();
  textRange.execCommand("cut");
 } else {
  alert("IE only!");
 }
}
//粘贴代码
function pastecode(obj) {
 if(document.all) {
  textRange=obj.createTextRange();
  textRange.execCommand("paste");
 } else {
  alert("IE only!");
 }
}

</script>
</head>

<body>
<form name="form1">
<textarea name="text" id="runcode0" cols="72" rows="9"></textarea><br />

<input type="button" value="运行代码" onClick="runcode(runcode0)">
<input type="button" value="保存代码" onClick="savecode(runcode0)">
<input type="button" value="复制代码" onClick="copycode(runcode0)">
<input type="button" value="剪切代码" onClick="cutcode(runcode0)">
<input type="button" value="粘贴代码" onClick="pastecode(runcode0)">
<input type="button" value="清空代码" onClick="document.form1.text.value='';">
</form>
</body>
</html>

转载请注明:天狐博客 » 在线运行HTML/JS代码预览html效果的实现

微信 OR 支付宝 扫描二维码
为天狐 打赏
非常感谢你的支持,哥会继续努力!
发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址