订阅本栏目 RSS您所在的位置: 深山工作室 > HTML > 正文

一个运行HTML文件的代码

网页教学网 2008/3/19 20:40:55 深山行者 字体: 浏览 9101

以下是引用片段:

<style type="text/css">
<!--
.sumit1 {width:98%;height:100%;background:#FFFFFF;border:1px solid red;color:red;font-weight:bold;font-size:14px;}
.sumit2 {width:98%;height:100%;background:#FFFFFF;border:1px solid green;color:green;font-weight:bold;font-size:14px;}
.sumit3 {width:98%;height:100%;background:#FFFFFF;border:1px solid blue;color:blue;font-weight:bold;font-size:14px;}
.sumit4 {width:98%;height:100%;background:#FFFFFF;border:1px solid #000;color:#000;font-weight:bold;font-size:14px;}
.sumit5 {width:98%;height:100%;background:#FFFFFF;border:1px solid blue;color:blue;font-weight:bold;font-size:14px;}
.sumit6 {width:98%;height:100%;background:#FFFFFF;border:1px solid #000;color:#000;font-weight:bold;font-size:14px;}
-->
</style>
<script>
//获取一个对象
function getByid(id) {
 if (document.getElementById) {
  return document.getElementById(id);
 } else if (document.all) {
  return document.all[id];
 } else if (document.layers) {
  return document.layers[id];
 } else {
  return null;
 }
}


//运行框操作
function creatID(DivID){
var objs=getByid(DivID).getElementsByTagName('textarea');
var inps=getByid(DivID).getElementsByTagName('input');
var buts=getByid(DivID).getElementsByTagName('button');
var labs=getByid(DivID).getElementsByTagName('label');
 for (i=0; i<objs.length; i++) {
  objs[i].id="runcode"+i;
  inps[i].id=i
  buts[i].id=i
  labs[i].id=i
 }
}
function runCode(obj){  //定义一个运行代码的函数,
   var code=getByid("runcode"+obj).value;//即要运行的代码。
   var newwin=window.open('','','');  //打开一个窗口并赋给变量newwin。
   newwin.opener = null // 防止代码对论谈页面修改
   newwin.document.write(code);  //向这个打开的窗口中写入代码code,这样就实现了运行代码功能。
   newwin.document.close();
}

//复制代码
function doCopy(obj) {
 if (document.all){
   textRange = getByid("runcode"+obj).createTextRange();
   textRange.execCommand("Copy");
   alert("代码已经复制到剪切板");
 }else{
   alert("此功能只能在IE上有效\n\n请在文本域中用Ctrl+A选择再复制")
 }
}
//另存代码
function saveCode(obj) {
        var winname = window.open('','','width=0,height=0,top=200,left=200px');
        winname.document.open('text/html', 'replace');
        winname.document.write(obj.value);
        winname.document.execCommand('saveas','','纯CSS简洁TAB.html');
        winname.close();
}

//剪切代码
function cut(obj) {
 if (document.all){
   textRange = getByid("runcode"+obj).createTextRange();
   textRange.execCommand("cut");
   alert("代码已经剪切到剪切板");
 }else{
   alert("此功能只能在IE上有效\n\n请在文本域中用Ctrl+A选择再剪切")
 }
}

//粘贴代码
function paste(obj) {
 if (document.all){
   textRange = getByid("runcode"+obj).createTextRange();
   textRange.execCommand("paste");
   alert("粘贴代码");
 }else{
   alert("此功能只能在IE上有效\n\n请在文本域中用Ctrl+v选择再粘贴")
 }
}
</script>

 <table width="100%" border="0" cellpadding="0" cellspacing="0">
 <form name=form1>
   <tr>
     <td height="530" colspan="6"><textarea name="text" id="runcode0" cols="72" rows="9" style="width:100%;height:98%;"> </TEXTAREA></td>
    </tr>
   <tr>
     <td height="53"><input type="button" value="运行代码" id="0" onClick="runCode(this.id)" class="sumit1"></td>
     <td><input type="button" value="保存代码" id="0" onClick="saveCode(runcode0)" class="sumit2"></td>
     <td><input type="button" value="复制代码" id="0" onClick="doCopy(this.id)" class="sumit3"></td>
     <td><input type="button" value="剪切代码" id="0" onClick="cut(this.id)" class="sumit4"></td>
     <td><input type="button" value="粘贴代码" id="0" onClick="paste(this.id)" class="sumit5"></td>
     <td><input type="button" value="清空代码" id="0" onClick="document.form1.text.value='';" class="sumit6"></td>
   </tr>
  </form>
 </table>
 

 

 

 


相关阅读
许愿墙开始重新设计。
九江市交通国际旅行社有限公司
04 正常使用运行深山留言板
诸城现代旅行社有限公司
网站终于在计划时间内完成了
四川省中国青年旅行社有限公司高新分社
旅行社网站模板默认风格5
06 iis中Server Application Error问题如何修复
更多信息>>栏目类别选择
百度小程序开发
微信小程序开发
微信公众号开发
uni-app
asp函数库
ASP
DIV+CSS
HTML
python
更多>>同类信息
dw里面查找替换使用正则删除sqlserver里面的CONSTRAINT
javascript获取浏览器指纹可以用来做投票
火狐Mozilla Firefox出现:无法载入您的Firefox配置文件 它可能已经丢失 或是无法访问 问题解决集合处理办法
DW设置之后更好用 DreamweaverCS编辑GB2312与UTF-8文件在代码视图中点击鼠标错位问题的解决办法
js指定日期加n天加n月加n年
jquery中动态生成的代码使用on hover事件时不出现效果
更多>>最新添加文章
dw里面查找替换使用正则删除sqlserver里面的CONSTRAINT
Android移动端自动化测试:使用UIAutomatorViewer与Selenium定位元素
抖音直播音挂载小雪花 懂车帝小程序
javascript获取浏览器指纹可以用来做投票
火狐Mozilla Firefox出现:无法载入您的Firefox配置文件 它可能已经丢失 或是无法访问 问题解决集合处理办法
在Android、iOS、Windows、MacOS中微信小程序的文件存放路径
python通过代码修改pip下载源让下载库飞起
python里面requests.post返回的res.text还有其它的吗
更多>>随机抽取信息
CSS或js实现行间交替背景色效果
简单的圆角实现方案
radio组选择详细
css解决中英混合链接下划线不对齐问题
微信小程序客服会话只能过button让用户主动触发
网页制作中关于浏览器宽度和高度的设定研究(转载)