abstract:<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>仿机器人聊天</title> </head> <body> <input type="text"
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>仿机器人聊天</title> </head> <body> <input type="text" name="info"> <button name="btn">提交</button> <ul> </ul> <script type="text/javascript"> //提取input标签 let info = document.getElementsByName('info')[0]; //控制台中输出 console.log(info) //提取button标签 let btn = document.getElementsByName('btn').item(0); //控制台中输出btn console.log(btn); //提取ul标签 let ul = document.getElementsByTagName('ul').item(0); //控制台中输出查看ul console.log(ul); btn.onclick = function(){ // 创建列表项li let li = document.createElement('li'); // 内容写入li中 li.innerHTML = info.value; // 写入li中内容进入ul列表中 ul.appendChild(li); // info 输入框的内容清空 info.value = null; info.value = ''; } </script> </body> </html>
Correcting teacher:天蓬老师Correction time:2018-12-20 14:10:18
Teacher's summary:这个案例,是考察对于dom元素的创建与内容填充