您的位置:首页 > Web前端 > JavaScript

JavaScript对文本框内容进行打印、另存为、运行及复制的代码

2012-03-09 19:48 441 查看
<script language=Jscript>

function run(obj){

if (f1.code.value==''||f1.code.value==' '){

alert("代码不能空!");obj.focus()}

else{

var winEx = window.open("", "winEx", "width=400,height=300,resizable=yes,top=0,left=0");

winEx.document.write(f1.code.value);winEx.document.close()}}

function Jia(){

document.f1.code.rows+=parseFloat(f1.h1.value)}

function Jian(ob){

if (ob.rows>3) document.f1.code.rows-=parseInt(f1.h1.value);

else alert('已接近最小值')}

function Exec(obj,cmd){

obj.select();document.execCommand(cmd)}

function Paste(obj){

obj.focus();document.execCommand('paste')}

function Exe(cmd){

document.execCommand(cmd)}

function view(){

window.location="view-source:"+window.location.href}

</script><style>body{

color:#063;font-family:arial;font-size:12}

textarea{

border:1 solid #000;font-family:arial;font-size:12;width:100%;color:red;margin:5 0}

</style>

<form name=f1>

<input type=button value='↓' onclick=Jia(code)>

<select onchange="h1.value=this.options[this.selectedIndex].value">

<option value=1>1</option><option value=2>2</option><option value=3>3</option></select>

<input type=button value='↑' onclick=Jian(code)>

<input type=button value='拷贝' onclick=Exec(code,'Copy')>

<input type=button value='剪切' onclick=Exec(code,'Cut')>

<input type=button value='粘贴' onclick=Paste(code)>

<input type=button value='清空' onclick=Exec(code,'Delete')>

<input type=button value='查看' onClick=view()>

<input type=button value='打印' onclick=Exe('print')>

<input type=button value='另存' onclick=Exe('SaveAs')>

<input type=button value='刷新' onclick=Exe('ReFresh')>

<input type=button value='打开' onclick=Exe('Open')>

<input value=1 name=h1 type=hidden><input name=h2 type=button>

<input type=button value=运行' onclick=run(code)>

<textarea name=code rows="20">Input Code ...</textarea></form>

<script>function show(){

var t=new Date();var h=t.getHours();var m=t.getMinutes();

var s=t.getSeconds();if(h<10)h="0"+h;if(m<10)m="0"+m;if(s<10)s="0"+s;

document.f1.h2.value=h+":"+m+":"+s;setTimeout("show()","1000")}show()

</script>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: