js编辑table td
2016-12-28 17:09
239 查看
1、table的view界面:
![](https://img-blog.csdn.net/20161228170617834?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGl1eHVleWk1MjE=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
2、转为edit界面:
![](https://img-blog.csdn.net/20161228170635069?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGl1eHVleWk1MjE=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
3、保存后的界面:
![](https://img-blog.csdn.net/20161228170650131?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGl1eHVleWk1MjE=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
4、在保存的时候,可以把整个html传递到后台;
<table id="table" class="ke-zeroborder" cellspacing="0" cellpadding="0" border="1">
<tbody>
<tr>
<td class="A">操作</td>
<td class="A">序号</td>
<td class="A">风险事件归类</td>
</tr>
</tbody>
</table>
<input type="button" value="编辑" name="edit" onclick="edit()"></input>
<input type="button" value="保存" name="save" onclick="mySave()"></input>
<script>
function test(obj)
{
var R1InnerHtml ='<tr class="R1"><td>  </td><td></td><td> </td><td></td><td></td><td></td><td></td><td></td><td></td></tr>';
var myStyle = '<style type="text/css">.A{width:90px;height:35px;}</style>';
var classFlag = obj.name;
var rowStartIndex = obj.parentNode.parentNode.rowIndex ;
var rowChildCount = document.getElementsByClassName(classFlag).length;
var rowLocated = rowStartIndex + rowChildCount;
var tableObj = document.getElementById("table");
var rowNew = tableObj.insertRow(rowLocated);
rowNew.innerHTML = R1InnerHtml;
}
function edit(){
var tdObj = document.getElementsByTagName("td");
for(var i = 0 ; i<tdObj.length; i++){
curObj = tdObj[i];
curObj.innerHTML = "<input type='text' value='" + curObj.innerText + "' name='b'/>";
}
}
function mySave(){
var tdObj = document.getElementsByTagName("td")[1].firstElementChild.value;
var tdObj = document.getElementsByTagName("td");
for(var i = 0 ; i<tdObj.length; i++){
var inputValue = tdObj[i].firstElementChild.value;
tdObj[i].innerText = inputValue;
}
var test = document.getElementById("table").outerHTML ;
test +=myStyle;
alert(test);
document.write(test);
var str ='';
for(var i in test){
str += i + ' = ' + test[i] + '\n\n';
}
alert(str);
}
</script>
<style type="text/css">
.A{width:90px;height:35px;}
</style>
2、转为edit界面:
3、保存后的界面:
4、在保存的时候,可以把整个html传递到后台;
<table id="table" class="ke-zeroborder" cellspacing="0" cellpadding="0" border="1">
<tbody>
<tr>
<td class="A">操作</td>
<td class="A">序号</td>
<td class="A">风险事件归类</td>
</tr>
</tbody>
</table>
<input type="button" value="编辑" name="edit" onclick="edit()"></input>
<input type="button" value="保存" name="save" onclick="mySave()"></input>
<script>
function test(obj)
{
var R1InnerHtml ='<tr class="R1"><td>  </td><td></td><td> </td><td></td><td></td><td></td><td></td><td></td><td></td></tr>';
var myStyle = '<style type="text/css">.A{width:90px;height:35px;}</style>';
var classFlag = obj.name;
var rowStartIndex = obj.parentNode.parentNode.rowIndex ;
var rowChildCount = document.getElementsByClassName(classFlag).length;
var rowLocated = rowStartIndex + rowChildCount;
var tableObj = document.getElementById("table");
var rowNew = tableObj.insertRow(rowLocated);
rowNew.innerHTML = R1InnerHtml;
}
function edit(){
var tdObj = document.getElementsByTagName("td");
for(var i = 0 ; i<tdObj.length; i++){
curObj = tdObj[i];
curObj.innerHTML = "<input type='text' value='" + curObj.innerText + "' name='b'/>";
}
}
function mySave(){
var tdObj = document.getElementsByTagName("td")[1].firstElementChild.value;
var tdObj = document.getElementsByTagName("td");
for(var i = 0 ; i<tdObj.length; i++){
var inputValue = tdObj[i].firstElementChild.value;
tdObj[i].innerText = inputValue;
}
var test = document.getElementById("table").outerHTML ;
test +=myStyle;
alert(test);
document.write(test);
var str ='';
for(var i in test){
str += i + ' = ' + test[i] + '\n\n';
}
alert(str);
}
</script>
<style type="text/css">
.A{width:90px;height:35px;}
</style>
相关文章推荐
- EXT.JS的PROXY放在哪里,STORE放在哪里,绝对是个技术活儿啊。
- SuperMap iClient for JavaScript查询过滤条件构建
- jsp中文乱码问题(get和post)
- js setTimeout
- 用js写倒计时
- 创建对象及原型模式
- 复杂表单转换JS对象 form2js插件介绍
- JsonOperate 帮助类
- JS面向对象实战(一)——创建一个新的函数对象的两种习惯
- JSP2自定义标签库技术
- three.js官方手册翻译【第二节WegGL和浏览器兼容性检测】
- javascript的Touch事件
- js 将Date 日期对象与时间戳互相转换
- JSP中Forward和Redirect之间的区别
- JSOUP选择器语法说明
- jspxcms bug表
- JSP的7个动作指令之plugin指令
- 繁简体转换js
- JS二分查找
- 【js运动学习】淡入淡出