jQuery动态添加与删除tr行实例代码
jQuery动态添加与删除tr行实例代码
发布时间:2016-12-30 来源:查字典编辑
摘要:这篇文章给大家分享的是一个用Jquery实现动态添加和删除tr行的小例子下面是实现的样子,当然没有样式:点击添加按钮可以添加一行:点击删除可...

这篇文章给大家分享的是一个用Jquery实现动态添加和删除tr行的小例子

下面是实现的样子,当然没有样式:

jQuery动态添加与删除tr行实例代码1

点击添加按钮可以添加一行:

jQuery动态添加与删除tr行实例代码2

点击删除可以删除本行:

jQuery动态添加与删除tr行实例代码3

基本功能是这样,下面是代码:

<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <> <script src="http://apps.bdimg.com/libs/jquery/1.6.4/jquery.js" type="text/javascript"></script> </head> <body> <table id="allDatas"> <tr> <th>选择图片</th> <th>图片名称</th> <th>描述</th> <th>操作</th> </tr> <tr> <td><input type="file" name="imageFile1"/></td> <td><input name="imageName"></input></td> <td><input name="note" /> </td> <td><a href="javascript:;"><font color='red'>删除</font></a> </td> </tr> </table> <button >添加</button> <script> function addCurrentRow() { var trcomp="<tr><td><input type='file' name='imageFile'/></td><td><input name='imageName'></input></td><td><input name='note' /></td><td><a href='javascript:;' onclick='deleteCurrentRow(this);'><font color='red'>删除</font></a></td></tr>"; $("#allDatas tr:last-child").after(trcomp); } function deleteCurrentRow(obj) { var isDelete=confirm("真的要删除吗?"); if(isDelete) { var tr=obj.parentNode.parentNode; var tbody=tr.parentNode; tbody.removeChild(tr); } } </script> </body> </html>

总结

以上就是jQuery动态添加与删除tr行的全部内容,希望本文的内容对大家的学习或者工作能有所帮助,如果有疑问大家可以留言交流。

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新Javascript教程学习
热门Javascript教程学习
编程开发子分类