<p> <label>描述:</label> <textarea cols="65" rows="10" onclick="Copy(this)" id="contents" readonly="readonly">{{task.description}}</textarea> </p> {% if task.content.code == "essay" %} <p> <label>子描述:</label> <textarea cols="65" rows="10" onclick="Copy(this)" readonly="readonly">{{task.original}}</textarea> </p> <style type="text/css"> .br{list-style:none; margin:130px 0 0 0 ; display: inline-block; background: #e3e3e3; border-radius:13px; border: 2px #D1E0F1 solid; width:130%; height: 170px; } .content{ text-align:center; line-height:95px; font-size: 18px; } </style> <script type="text/JavaScript"> function Copy(e){
X var e=document.getElementById("contents"); 同一个事件 id只能存在一个
var copy = e.getAttribute("copy");
if(copy != "1"){ e.select(); document.execCommand("Copy"); e.setAttribute("copy", "1"); window.alert = function(str) { var shield = document.createElement("DIV"); //创建提示窗口的div shield.id = "shield"; var alertFram = document.createElement("DIV"); alertFram.id="alertFram"; alertFram.style.position = "absolute"; alertFram.style.left = "50%"; alertFram.style.top = "0"; alertFram.style.marginLeft = "-140px"; alertFram.style.marginTop = "120px"; alertFram.style.textAlign = "center"; strHtml = '<div class="br">'; strHtml += '<p class="content">'+str+'</p>'; strHtml += '<input type="button" value="确 定" onclick="doOk()" class="btn"/></li>'; strHtml += '</div>'; alertFram.innerHTML = strHtml; document.body.appendChild(alertFram); document.body.appendChild(shield); this.doOk = function(){ alertFram.style.display = "none"; shield.style.display = "none"; }; alertFram.focus(); document.body.onselectstart = function(){return false;}; }; alert('文本已成功复制到剪贴板,ctrl + v 粘贴'); } } </script>