jQuery實(shí)現(xiàn)用戶信息表格的添加和刪除功能
1、瀏覽器界面

一個簡單的用戶信息操作
2、html代碼
<body>
<form name="userForm">
<center>
用戶錄入
<br />
用戶名:
<input id="username" name="username" type="text" size=15 />
E-mail:
<input id="email" name="email" type="text" size=15 />
電話:
<input id="tel" name="tel" type="text" size=15 />
<input type="button" value="添加" id="btn_submit" />
<input type="button" value="刪除所有" id="btn_removeAll" />
</center>
</form>
----------------------------
<hr />
<table border="1" align="center" cellpadding=0 cellspacing=0 width=400>
<thead>
<tr>
<th>用戶名</th>
<th>E-mail</th>
<th>電話</th>
<th>操作</th>
</tr>
</thead>
----------------------------
<tbody id="userTbody">
<tr>
<td>喬峰</td>
<td>qiao@163.com</td>
<td>18212345678</td>
<td>
<a href='#' class='myClz'>刪除</a>
</td>
</tr>
</tbody>
----------------------------
</table>
</body>
3、jQuery實(shí)現(xiàn)
$(function () {
$("#btn_submit").click(function () {
// 獲取用戶輸入的值
var usernameVal = $("#username").val();
var emailVal = $("#email").val();
var telVal = $("#tel").val();
var tr = "<tr><td>" + usernameVal + "</td><td>" + emailVal
+ "</td><td>" + telVal
+ "</td><td><a href='#' class='myClz'>刪除</a></td></tr>";
$("#userTbody").append(tr);
});
// 全部刪除
$("#btn_removeAll").click(function () {
$("#userTbody").empty();
});
//刪除一行數(shù)據(jù)
/*click只對本身頁面有的元素有作用,對于后面新加的元素,不起作用
$(".myClz").click(function() {
console.log(123);
});
*/
/*選擇id=userTbody元素下所有樣式名含有myClz的標(biāo)簽,并添加click事件
*當(dāng)點(diǎn)擊后,向上一級找到tr元素,然后刪除
*/
$('#userTbody').on('click', ".myClz", function () {
$(this).closest('tr').remove();
});
});
總結(jié)
以上所述是小編給大家介紹的jQuery實(shí)現(xiàn)用戶信息表格的添加和刪除功能,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關(guān)文章
Jquery網(wǎng)頁內(nèi)滑動緩沖導(dǎo)航的實(shí)現(xiàn)代碼
這篇文章主要介紹了Jquery網(wǎng)頁內(nèi)滑動緩沖導(dǎo)航的實(shí)現(xiàn)代碼,實(shí)現(xiàn)滑動緩沖的方式實(shí)現(xiàn)頁內(nèi)導(dǎo)航,用戶體驗(yàn)大大提升需要的朋友可以參考下2015-04-04
jQuery實(shí)現(xiàn)的五星點(diǎn)評功能【案例】
這篇文章主要介紹了jQuery實(shí)現(xiàn)的五星點(diǎn)評功能,結(jié)合具體實(shí)例形式分析了jQuery事件響應(yīng)及頁面元素屬性動態(tài)操作實(shí)現(xiàn)五星點(diǎn)評功能相關(guān)操作技巧,需要的朋友可以參考下2019-02-02
關(guān)于 jQuery Easyui異步加載tree的問題解析
想要實(shí)現(xiàn)從本地中加載json文件,通過事件來動態(tài)的插入到ul中時,遇到了一小bug,下面小編給大家解答下2016-12-12
使用jquery DataTable和ajax向頁面顯示數(shù)據(jù)列表的方法
今天小編就為大家分享一篇使用jquery DataTable和ajax向頁面顯示數(shù)據(jù)列表的方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-08-08
jQuery實(shí)現(xiàn)仿美橙互聯(lián)兩級導(dǎo)航菜單的方法
這篇文章主要介紹了jQuery實(shí)現(xiàn)仿美橙互聯(lián)兩級導(dǎo)航菜單的方法,實(shí)例分析了jQuery操作css及setTimeout等實(shí)現(xiàn)導(dǎo)航菜單的技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-03-03

