주소복사 소스 확인 부탁드립니다. 채택완료
<?php echo $row[re_addr1];?>
저희 사이트에 주소를 보여주는 소스입니다 이거 옆에 버튼을 생성해서 버튼을 누르면 주소를 복사했습니다라는 걸 넣고 싶은데 어떻게 해야하나요?
<button onclick="copy_to_clipboard()">주소복사</button>
<br/>
<input type="text" id="myInput" value="<?php echo $re_addr1; ?>">
<script>
function copy_to_clipboard() {
$("#myInput").select();
document.execCommand("copy");
alert('복사되었습니다.');
}
</script>
이렇게 하면되나요? 그누보드 보고 따라해봤습니다
답변 2개
채택된 답변
+20 포인트
답변에 대한 댓글 4개
5년 전
<?php $re_addr1 = $row['re_addr1'];?> 을 대입해주시거나 input value를 변경하시거나 하시면 됩니다.
5년 전
<?php echo $row[re_addr1];?>
<button onclick="copy_to_clipboard()">주소복사</button>
<br/>
<input type="text" id="myInput" value="<?php echo $row[re_addr1];?>">
<script>
function copy_to_clipboard() {
$("#myInput").select();
document.execCommand("copy");
alert('복사되었습니다.');
}
</script>
이렇게 했는데되도 안되네요 ㅋㅋ 감사합니다
<button onclick="copy_to_clipboard()">주소복사</button>
<br/>
<input type="text" id="myInput" value="<?php echo $row[re_addr1];?>">
<script>
function copy_to_clipboard() {
$("#myInput").select();
document.execCommand("copy");
alert('복사되었습니다.');
}
</script>
이렇게 했는데되도 안되네요 ㅋㅋ 감사합니다
5년 전
JQuery 먼저 로드되야지 정상 작동합니다 의존성 없게 할려면 아래처럼하시면 됩니다.
<script>
function copy_to_clipboard() {
document.getElementById("myInput").select();
document.execCommand("copy");
alert('복사되었습니다.');
}
</script>
<script>
function copy_to_clipboard() {
document.getElementById("myInput").select();
document.execCommand("copy");
alert('복사되었습니다.');
}
</script>
댓글을 작성하려면 로그인이 필요합니다.
5년 전
로그인 후 평가할 수 있습니다
답변에 대한 댓글 2개
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인