JS裡面的innerHTML

來源:互聯網
上載者:User

標籤:btn   click   body   blog   val   元素   替換   輸入框   標題   

1.在輸入框輸入一句話

2.點擊按鈕,輸入框裡面的內容會顯示在下面

 1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 5 <title>無標題文檔</title> 6  7 <script> 8 /* 9     HTML 的屬性操作:讀、寫10         屬性名稱:11         屬性值:12         13         讀操作:擷取、找到14         元素.屬性名稱15         16         寫操作:"添加?"、替換、修改17         元素.屬性名稱 = 新的值18         19         oP.innerHTML                    => 讀取p裡面所有的html代碼20         oP.innerHTML = 123;        => 替換p裡面所有的html代碼21         22 */23 window.onload = function (){24     var oBtn = document.getElementById(‘btn1‘);25     var oText = document.getElementById(‘text1‘);26     var oP = document.getElementById(‘p1‘);27 28     oBtn.onclick = function (){29         // oImg.src = oText.value;30         // alert( oP.innerHTML );31         oP.innerHTML = oText.value;32     };33 };34 </script>35 36 </head>37 38 <body>39 40 <input id="text1" type="text" />41 <input id="btn1" type="button" value="按鈕" />42 <p id="p1">這是一些文字</p>43 44 </body>45 </html>
範例程式碼:

 

JS裡面的innerHTML

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.