텍스트 복사 / 붙여넣기 자바스크립트
2018. 3. 9. 16:01ㆍJavascript/Javascript+jQuery
반응형
<html>
<head>
<script>
function pasteboard(){
textRange = document.body.createTextRange();
textRange.moveToElementText(test);
textRange.execCommand("paste");
}
function clipboard(){
holdtext.createTextRange().execCommand("Copy");
}
</script>
</head>
<body>
<textarea id="holdtext"></textarea>
<button onclick="clipboard();">복사</button>
<button onclick="pasteboard();">가져오기</button>
<textarea id="test"></textarea>
</body>
</html>
<div id="divid">Hello This div content have to be select.</div>
<button onclick="selectText('divid');">Select Div</button>
function selectText(element) {
var doc = document
, text = doc.getElementById(element)
, range, selection
;
if (doc.body.createTextRange) { //ms
range = doc.body.createTextRange();
range.moveToElementText(text);
range.select();
} else if (window.getSelection) { //all others
selection = window.getSelection();
range = doc.createRange();
range.selectNodeContents(text);
selection.removeAllRanges();
selection.addRange(range);
}
}
<textarea id="input">Some text to copy.</textarea>
<button id="copy-button">Copy</button>
<script>
var input = document.getElementById("input");
var button = document.getElementById("copy-button");
button.addEventListener("click", function (event) {
event.preventDefault();
input.select();
document.execCommand("copy");
});
</script>
반응형
'Javascript > Javascript+jQuery' 카테고리의 다른 글
jQuery checkbox 컨트롤 (0) | 2018.03.21 |
---|---|
체크박스 전체선택,전체해제,선택반전, 체크박스 선택갯수 확인 및 값 확인 (0) | 2018.03.19 |
Onclick selection of textbox data (0) | 2018.03.10 |
TEXT to Clipboard on a Button-Click (0) | 2018.03.10 |
체크박스 클릭하면 텍스트 입력 필드 복사하기 예제 (0) | 2018.03.05 |