js和jstl标签混用,太强大了!
来源:互联网 发布:阿里云 数据库 用法 编辑:程序博客网 时间:2024/06/02 08:57
//初始状态对指标进行赋值$(document).ready(function(){ <c:forEach items="${details}" var="item"> var indicatorId = "${item.indicatorId}"; var indicatorName = "${item.indicatorName}"; var indicatorWeight = "${item.indicatorWeight}"; var indicatorLevel = "${item.indicatorLevel}"; var parentIndicatorId = "${item.parentIndicatorId}"; //取得table对象 // var tabObj = document.getElementById("tableId"); var indicatorDivs=$("#indicatorDivs").find("tbody"); var tabObj=indicatorDivs[0]; var cloneRow = document.getElementById("clonetr"); //循环 向table增加新行 //var newRow = tabObj.insertRow(rowCount++); var newRow= cloneRow.cloneNode(); tabObj.appendChild(newRow); //每行的新列值 newRow.insertCell(0).innerHTML=indicatorId; newRow.insertCell(1).innerHTML=indicatorName; newRow.insertCell(2).innerHTML=indicatorWeight; newRow.insertCell(3).innerHTML=indicatorLevel; newRow.insertCell(4).innerHTML=parentIndicatorId; newRow.insertCell(5).innerHTML="<a class='btnDel'>删除</a>"; newRow.cells[5].onclick = function(){ //删除行 deleteIndicator(this.parentNode.firstChild.innerHTML); var indicators=$("#indicatorDivs").find("tbody"); var tabObj=indicators[0]; tabObj.rows[this.parentNode.rowIndex].remove(); }; newRow.style.visibility="visible"; </c:forEach> });
此处有一个问题就是,无法将删除事件加上,原因:写入table 行比较慢,只需要加载所有的DOM结构,在浏览器把所有的HTML放入DOM tree之前就执行js效果。包括在加载外部图片和资源之前,即,dom加载在前,而窗体加载在ready事件之后。
这事件是加在单元格的,理论上点击链接是会冒泡的,把事件加到链接试试吧,你的代码是在单元格上
经过高人指点之后,修改如下即可。
//初始状态对指标进行赋值$(document).ready(function(){ //对修改页面指标信息进行填充 <c:forEach items="${details}" var="item"> var indicatorId = "${item.indicatorId}"; var indicatorName = "${item.indicatorName}"; var indicatorWeight = "${item.indicatorWeight}"; var indicatorLevel = "${item.indicatorLevel}"; var parentIndicatorId = "${item.parentIndicatorId}"; var indicatorDivs=$("#indicatorDivs").find("tbody"); var tabObj=indicatorDivs[0]; var cloneRow = document.getElementById("clonetr"); //循环 向table增加新行 var newRow= cloneRow.cloneNode(); tabObj.appendChild(newRow); //每行的新列值 newRow.insertCell(0).innerHTML=indicatorId; newRow.insertCell(1).innerHTML=indicatorName; newRow.insertCell(2).innerHTML=indicatorWeight; newRow.insertCell(3).innerHTML=indicatorLevel; newRow.insertCell(4).innerHTML=parentIndicatorId; newRow.insertCell(5).innerHTML="<a class='btnDel' href='javascript:addDelete(\""+indicatorId+"\");'>删除</a>"; newRow.style.visibility="visible"; </c:forEach> });//为href增加删除事件function addDelete(indicatorId){ var index = 1000;//存储所在行索引 deleteIndicator(indicatorId); //后台删除 var tabObj = document.getElementById("tbodyId"); var len = tabObj.rows.length; //获取指标所在行索引 for(var i=0;i<len;i++){ if(indicatorId==tabObj.children[i].cells[0].textContent){ index = i; break; } } tabObj.rows[index].remove();//前台删除}
由于无法传参,最后使用转义字符完成,又学习到一点小知识。
0 0
- js和jstl标签混用,太强大了!
- wget太强大了
- Webzip 太强大了
- libusb太强大了
- JavaScript连接SqlServer实现CRUD操作。js太强大了
- 太强大的回帖了................................
- Linux太自由了,也太不强大了
- struts标签和el混用问题
- Google App Engine太强大了
- 中国综合战争实力太强大了
- CMD批处理循环,太强大了
- CMD批处理循环,太强大了
- CMD批处理循环,太强大了
- JSTL标签和I18N
- jstl和自定义标签
- JS中使用JSTL标签
- 行级标签和基本的图文混用
- jstl 和js
- Arraylist 逆置,循环右移,循环左移
- 回文词
- Flip Game
- ubuntu: Unable to correct problems, you have held broken packages 解决方案
- VS2013生成DLL却没有lib文件
- js和jstl标签混用,太强大了!
- 吐槽iOS国际化:关于NSLocalizedString的使用
- eclipse中如何在当前工程中查找一个字符串
- String.format参加字符串拼接大比拼
- R语言与机器学习学习笔记(分类算法)(1)K-近邻算法
- jQuery 事件
- HDU 1754 I Hate It!(线段树)
- SCU2016-07 T题 prim算法
- jeasyui插件扩展datagrid-filter的改善