以下是引用片段:
<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>
|