哈哈, 终于被偶搞定了:
<!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>
<title>粘贴为HTML代码</title>
<style type="text/css">
</style>
<script type="text/javascript">
</script>
</head>
<body class="body">
<h2 style="border-bottom:solid 1px black;">粘贴为HTML代码</h2>
<form id="Form1" action="">
<div id="divForm">
<textarea style="width:500px; height:100px;" id="text1"></textarea>
<input type="button" id="btnTest" value="粘贴" style="margin:10px 0px 10px 0px; display:block;" />
<iframe id="w2" src="about:blank" style="width:500px; height:200px;"></iframe>
</div>
</form>
<script type="text/javascript" >
var btnTest=document.getElementById("btnTest");
var text1=document.getElementById("text1");
//var w2=document.getElementById("w2");//如果不注释掉这行代码, 代码将不能执行. 反正粘贴板只有IE支持, 这句本来就是多余的.
w2.document.designMode="On";
btnTest.onclick=function(){
w2.document.body.innerHTML="";
w2.focus();
document.execCommand("Paste");
text1.value=w2.document.body.innerHTML;
}
text1.onpaste=function(){
btnTest.onclick();
return false;
}
</script>
</body>
</html>
<!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>
<title>粘贴为HTML代码</title>
<style type="text/css">
</style>
<script type="text/javascript">
</script>
</head>
<body class="body">
<h2 style="border-bottom:solid 1px black;">粘贴为HTML代码</h2>
<form id="Form1" action="">
<div id="divForm">
<textarea style="width:500px; height:100px;" id="text1"></textarea>
<input type="button" id="btnTest" value="粘贴" style="margin:10px 0px 10px 0px; display:block;" />
<iframe id="w2" src="about:blank" style="width:500px; height:200px;"></iframe>
</div>
</form>
<script type="text/javascript" >
var btnTest=document.getElementById("btnTest");
var text1=document.getElementById("text1");
//var w2=document.getElementById("w2");//如果不注释掉这行代码, 代码将不能执行. 反正粘贴板只有IE支持, 这句本来就是多余的.
w2.document.designMode="On";
btnTest.onclick=function(){
w2.document.body.innerHTML="";
w2.focus();
document.execCommand("Paste");
text1.value=w2.document.body.innerHTML;
}
text1.onpaste=function(){
btnTest.onclick();
return false;
}
</script>
</body>
</html>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货