没有合适的资源?快使用搜索试试~ 我知道了~
首页JS实现动态增加和删除li标签行的实例代码
资源详情
资源评论
资源推荐
JS实现动态增加和删除实现动态增加和删除li标签行的实例代码标签行的实例代码
下面小编就为大家带来一篇JS实现动态增加和删除li标签行的实例代码。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
如下所示:如下所示:
function addDepartment()
{
<span style="white-space:pre"> </span>var x = document.getElementById('department');
<span style="white-space:pre"> </span>var l = x.childNodes.length;
<span style="white-space:pre"> </span>var li = document.createElement("li");
<span style="white-space:pre"> </span>li.className = "list_nr_bg";
<span style="white-space:pre"> </span>li.innerHTML = "<span class='nr6'><select name='institute'><c:if test='${baseInstitutes !=null}'><c:forEach items='${baseInstitutes}' var='baseInstitute'><option value='${baseInstitute.id}'>${baseInstitute.instituteName}</option></c:forEach></c:if></select></span><span class='nr6'>专业:</span><span class='nr6'><input name='specialty' type='text'></span><span><input type='button' onclick='deleteDepartment(this)' value='删除'></span>";
<span style="white-space:pre"> </span>x.appendChild(li);
}
function deleteDepartment(obj)
{
<span style="white-space:pre"> </span>if(window.confirm("确认删除吗?")){
<span style="white-space:pre"> </span>var li = obj.parentNode.parentNode; //获得当前行
<span style="white-space:pre"> </span>var ul = li.parentNode;//获得上一级标签
<span style="white-space:pre"> </span>ul.removeChild(li); //删除当前行
<span style="white-space:pre"> </span>} else {
<span style="white-space:pre"> </span>return false;
<span style="white-space:pre"> </span>}
}
HTML::
<ul id="department">
<span style="white-space:pre"> </span><li class="list_nr_bg">
<span style="white-space:pre"> </span><span class="nr6">所属院系:</span>
<span style="white-space:pre"> </span><span><input type="button" onclick="addDepartment()" value="增加"></span>
<span style="white-space:pre"> </span></li>
<span style="white-space:pre"> </span><li class="list_nr_bg">
<span style="white-space:pre"> </span><span class="nr6">
<span style="white-space:pre"> </span><select name="institute">
<span style="white-space:pre"> </span><c:if test="${baseInstitutes !=null}">
<span style="white-space:pre"> </span><c:forEach items="${baseInstitutes}" var="baseInstitute">
<span style="white-space:pre"> </span><option value="${baseInstitute.id}">${baseInstitute.instituteName}</option>
<span style="white-space:pre"> </span></c:forEach>
<span style="white-space:pre"> </span></c:if>
<span style="white-space:pre"> </span>/select>
<span style="white-space:pre"> </span></span>
<span style="white-space:pre"> </span><span class="nr6">专业:</span>
<span style="white-space:pre"> </span><span class="nr6"><input name="specialty" type="text"></span>
<span style="white-space:pre"> </span></li></ul>
以上就是小编为大家带来的JS实现动态增加和删除li标签行的实例代码全部内容了,希望大家多多支持我们~
weixin_38688403
- 粉丝: 3
- 资源: 928
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- stc12c5a60s2 例程
- Android通过全局变量传递数据
- c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf
- 建筑供配电系统相关课件.pptx
- 企业管理规章制度及管理模式.doc
- vb打开摄像头.doc
- 云计算-可信计算中认证协议改进方案.pdf
- [详细完整版]单片机编程4.ppt
- c语言常用算法.pdf
- c++经典程序代码大全.pdf
- 单片机数字时钟资料.doc
- 11项目管理前沿1.0.pptx
- 基于ssm的“魅力”繁峙宣传网站的设计与实现论文.doc
- 智慧交通综合解决方案.pptx
- 建筑防潮设计-PowerPointPresentati.pptx
- SPC统计过程控制程序.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0