注册 登录
编程论坛 JavaScript论坛

如何让3个button别作用?

Z89 发布于 2024-03-23 21:22, 205 次点击

                             <div class="pwd3"><button onClick="copyText()"><strong>製表單1</strong></button></div>                            <hr>                            <div id="myDiv" class="pwd2"><p>表單1內容:xxxxx<br /></div>                            <div class="pwd4"><button onClick="copyText()"><strong>製表單2</strong></button></div>                            <hr>                            <div id="myDiv1" class="pwd2"><p>表單2內容:xxxx<br /></div><script>        function copyText() {            // 選取<div>元素的內容            const divText = document.getElementById("myDiv").textContent;            // 建立一個臨時的文本區域元素            const tempTextarea = document.createElement("textarea");            tempTextarea.value = divText;            // 將文本區域元素加入到DOM中            document.body.appendChild(tempTextarea);            // 選取文本區域內的文字            tempTextarea.select();            // 複製選取的文字到剪貼板            document.execCommand("copy");            // 刪除臨時的文本區域元素            document.body.removeChild(tempTextarea);            // 顯示複製成功的提示            alert("表單已複製");        }    </script>   

1 回复
#2
emt10452024-05-20 19:08
看不清楚代码,能不能格式化一下
1