<p title="">嗨,你的title</p>
Assign "Hi, your title" to title
光阴似箭催人老,日月如移越少年。
var elem = document.querySelector("p"); elem.setAttribute("title", elem.innerText);
$("p").attr("title",$("p").text());
I don’t know what specific function you want, but if you want to assign a value, you can:
<p title="" class="title">赋值啊啊啊啊</p> <script> let txt = $('.title').text(); $('.title').attr('title',txt); </script>
$("p").attr("title",$("p").text());
I don’t know what specific function you want, but if you want to assign a value, you can: