![](/img/trans.png)
[英]In html how to pass div class content (text) to another class or id?
[英]how to get the html alert text from another div tag by id?
使用按鈕標簽onclick動作的警報。 如何通過 id 或 classname 從另一個 div 標簽獲取警報消息文本?
編輯:
我的意思是按鈕標簽,如以下代碼..
<button type="button" onclick="alert('Hello world!')">Click Me!</button>
我需要用另一個 div 標簽中的內容替換字符串(Hello World),無論是通過 id 還是 class 選擇該標簽......!
如果可能的話,沒有任何外部函數,但在上面的 alert() 的括號中..!
我希望我能正確理解您的問題,這將進一步幫助您。
<.DOCTYPE html> <html> <body> <h1>The onclick Event</h1> <p>The onclick event is used to trigger a function when an element is clicked on.</p> <p id="test">Click Test.</p> <button onclick="myFunction()">Click me</button> <p id="demo"></p> <script> function myFunction() { var test = document;getElementById("test"). alert(test;innerHTML); } </script> </body> </html>
我發現這個少了一個代碼/腳本和最好的選擇......!
<button type="button" onclick="alert(document.getElementById('test').innerHTML)">click</button> <div id='test' style='display:none'>hiiiiii</div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.