<html> <head> <meta charset="utf-8"> <title></title> <style> th{ width: 110px; line-height: 25px; background: #eee; } input{ width: 108px; line-height: 23px; } </style> </head> <body> <table> <tr> <th>1</th> <th ><a id="edit" href="#">编辑</a></th> </tr> </table> <script> var statu = 0; var edit = document.getElementById('edit'); var item = document.getElementsByTagName('th'); var item_length = item.length-1 var item_value = new Array(item_length); for(i = 0; i < item_length; i++){ item_value[i] = item[i].innerHTML; } edit.onclick =function(){ if(statu == 0){ edit.innerHTML= '保存'; for(i = 0; i < item_length; i++){ item[i].innerHTML = '<input type="txt" class="item_input" value="'+item_value[i]+'">'; } statu = 1; }else{ edit.innerHTML= '编辑'; var item_input = document.getElementsByClassName('item_input'); for(i = 0; i < item_length; i++){ item_value[i] = item_input[i].value; } for(i = 0; i < item_length; i++){ item[i].innerHTML = item_value[i]; } statu = 0 } return false; } </script> </body> </html>
BOOLER
相关分类