粘貼爲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.οnclick=function(){
        w2.document.body.innerHTML="";
        w2.focus();
        document.execCommand("Paste");
        text1.value=w2.document.body.innerHTML;
    }
    text1.οnpaste=function(){
        btnTest.onclick();
        return false;
    }
</script>
</body>
</html>

 

發佈了31 篇原創文章 · 獲贊 4 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章