iam不理解如何在點擊textarea後立即複製到clickboard ..我的意思是它應該選擇它裏面的所有內容,然後它應該彈出並且問一些'press ctrl c'複製到剪貼板..onclick全選textarea
我已經有,但不能選擇文本區域全文,並應複製到剪貼板代碼..
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript">
function myfunc2() {
var selectedobj=document.getElementById('showthis');
if(selectedobj.className=='hide'){ //check if classname is hide
selectedobj.style.display = "block";
selectedobj.readOnly=true;
selectedobj.className ='show';
}else{
selectedobj.style.display = "none";
selectedobj.className ='hide';
}
}
function copyToClipboard (text) {
window.prompt ("Copy to clipboard: Ctrl+C, Enter", text);
}
function select_all()
{
// alert(document.getElementById("showthis").value);
var text_val=eval("document.getElementById('showthis').value");
text_val.focus();
var copy = text_val.select();
window.prompt ("Copy to clipboard: Ctrl+C, Enter", copy);
}
</script>
</head>
<body>
<label onclick="myfunc2()">Click here</label>
<textarea id="showthis" style="display:none" class="hide" onclick="select_all()" readonly>dfdsfsfasdfdsfsfasdfssdfsfasf</textarea>
</body>
</html>
任何人都可以請看看這個。 ..
編輯: 我只需要Javascript代碼(不是JQuery的)
這是幹什麼的:'eval(「document.getElementById('showthis')。value」);'? –
它顯示你的textarea的全文。你究竟在做什麼? – polin
@Asad它沒有在textarea中選擇全文,也沒有得到該剪貼板彈出.. – Otero