摘要:<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>模擬實(shí)時(shí)聊天</title> </head> <body> <input type="text"
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>模擬實(shí)時(shí)聊天</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'); //判斷輸入是否為空 if ( input.value==0) { alert('輸入為空!');//輸入為空彈出提示 }else{ li.innerHTML = input.value;//將獲取的輸入寫入li ul.appendChild(li);//將li插入ul input.value ='';//清空輸入框 } } </script> </body> </html>
批改老師:韋小寶批改時(shí)間:2019-01-20 09:19:10
老師總結(jié):寫的還是很不錯(cuò) 很基礎(chǔ)的一個(gè)小案例 課后沒事記得要多練習(xí)哦