摘要:首先,獲取輸入框(input)、提交按鈕(button)、輸出列表項(ul); 其次,通過button按鈕點擊事件在ul列表項中添加li元素; 再次,獲取input框中的內(nèi)容,并顯示到列表項中,當再次點擊按鈕時清空 輸入框中的內(nèi)容。 <!DOCTYPE html> <html lang="en&quo
首先,獲取輸入框(input)、提交按鈕(button)、輸出列表項(ul); 其次,通過button按鈕點擊事件在ul列表項中添加li元素; 再次,獲取input框中的內(nèi)容,并顯示到列表項中,當再次點擊按鈕時清空 輸入框中的內(nèi)容。 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>實戰(zhàn)熱身</title> </head> <body> <input type="text" name="info"> <button>提交</button> <ul></ul> <script> let input = document.getElementsByName('info')[0]; let button = document.getElementsByTagName('button')[0]; let ul = document.getElementsByTagName('ul')[0]; button.onclick = function () { let li = document.createElement('li'); li.innerHTML = input.value; ul.appendChild(li); input.value = ''; } </script> </body> </html>
批改老師:滅絕師太批改時間:2019-01-26 09:28:04
老師總結(jié):作業(yè)比較簡單,下次完成這樣的作業(yè),需要帶上基本布局樣式