2017.11.14作业

来源:互联网 发布:变量被优化掉 编辑:程序博客网 时间:2024/05/17 20:28
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Document</title></head><body>姓名:<input type="text" id="name" />联系方式:<input type="text" id="email" />年龄:<input type="text" id="age" /><input type="button" value="添加用户" onclick="addUser()"/><br /><br /><hr /><br /><table id="userTable" align="center" border=1 cellspacing=0 cellpadding=5 width="50%">   <tr>   <th>姓名</th>   <th>联系方式</th>   <th>年龄</th>   <th>操作</th>      </tr>   <tr>   <td>测试</td>   <td>sn@dwd</td>   <td>18</td>   <td>   <input type="button" value="删除" onClick="removeUser(this)" />   </td>      </tr></table><script type="text/javascript">function addUser(){var name = document.getElementById('name').value;var email = document.getElementById('email').value;var age = document.getElementById('age').value;var html1 = "<tr><td>"+name+"</td><td>"+email+"</td><td>"+age+"</td><td><input type='button' value='删除' onclick='removeUser()' /></td></tr></table>";var newhtml = document.getElementById('userTable').innerHTML+html1;document.getElementById('userTable').innerHTML = newhtml;}function removeUser(obj){var removeLine = obj.parentNode.parentNode;removeLine.parentNode.removeChild(removeLine);}</script></body></html>

原创粉丝点击