我在這里有多個值,我使用 php 從 for 回圈中列印,所以我不想通過單擊此符號來選擇和復制值,以及如何獲取加號旁邊的每個 div 的值的問題。那么除了在這個鏈接中使用<select>和之外還有其他方法嗎
我有復制 div 內容的 Javascript 代碼,它只識別第一個列印值
function func_keywords(){
const span = document.querySelector("div");
span.onclick = function() {
document.execCommand("copy");
}
span.addEventListener("copy", function(event) {
event.preventDefault();
if (event.clipboardData) {
event.clipboardData.setData("text/plain", span.textContent);
console.log(event.clipboardData.getData("text"));
alert(span);
}
});
}
這是 PHP 代碼,不管在里面使用 css
<div id="copying_keywords" > $Youtube_tags_arr[$j $i]
"<button id=\"keywords\" onclick=\"func_keywords()\" type=\"button\" class=\"btn btn-default btn-sm\"> <span class=\"\"></span> <i class=\"fa-solid fa-plus\"></i> </button> </div>
uj5u.com熱心網友回復:
您需要在回圈中的事件中更改func_keywords()為以獲取按鈕旁邊的 div 的值func_keywords(this)onclick
并更改您的 js 功能
<script>
function func_keywords(e){
var value_from_div = e.parentElement.innerText; // value from div
//.. you code for add to clipboard
}
</script>
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/441663.html
標籤:javascript php jQuery
