日期:2014-05-17  浏览次数:20785 次

页面前端小问题,请各位帮忙。人在线 100分
JScript code
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">  
<HTML>  
<HEAD>  
<TITLE> New Document </TITLE>  
<META NAME="Generator" CONTENT="EditPlus">  
<META NAME="Author" CONTENT="">  
<META NAME="Keywords" CONTENT="">  
<META NAME="Description" CONTENT="">  
<script>  
 var i=0  

 function b(){
    
     var m=obj.parentElement.parentElement.rowIndex+1;
 
    m.removeAttribute("readOnly"); 
    

      


 }
  


 function insert_row(){ 
 
 
  i ++   
  R = tbl.insertRow()   
  C = R.insertCell()   
  C.innerHTML = "第"+i+"个文件"   
  C = R.insertCell()   
  C.innerHTML = "<input value='123' readOnly ondblclick='b();'>"
    C = R.insertCell()   
  C.innerHTML = "<input value='123' readonly>"  
    C = R.insertCell()   
  C.innerHTML = "<input value='123' readonly>"  
    C = R.insertCell()   
  C.innerHTML = "<input value='123' readonly>"  
    C = R.insertCell()   
  C.innerHTML = "<input value='123' readonly>"  
  C = R.insertCell()   
  C.innerHTML = "项目动态"  
  C = R.insertCell()   
  C.innerHTML = "<input >"  
 }   
 function deleteRow(obj){   
   var flag=confirm("请问要确认删除吗?") 
   if(flag){
 // alert(obj.parentElement.parentElement.rowIndex+1);   
  tbl.deleteRow(obj.parentElement.parentElement.rowIndex);
  

            }
 }   
</script>  
</HEAD>  
  
<BODY>  

  <form>
<input type='button'  value='删除' onclick='deleteRow(this)'>
  </form>
<input type="button" value="插入" onclick="insert_row()">    
  
<table name='tbl' id="tbl" border="1" width=300>    
</table>    
</BODY>  
</HTML>  

 



我现在的表格能够自动添加 也可以删除。 但是我想实现 选中哪行,就自动删除哪行。请各位帮忙,小弟诚惶诚恐。
人在线。


------解决方案--------------------
HTML code

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">  
<HTML>  
<HEAD>  
<TITLE> New Document </TITLE>  
<META NAME="Generator" CONTENT="EditPlus">  
<META NAME="Author" CONTENT="">  
<META NAME="Keywords" CONTENT="">  
<META NAME="Description" CONTENT="">  
<script>  
 var i=0;
 var selectedRow;
 function b(){
     var m=obj.parentElement.parentElement.rowIndex+1;
     m.removeAttribute("readOnly"); 
  
 }
  
 function insert_row(){ 
 
  i ++   
  R = tbl.insertRow() ;
  
  R.onclick = function (){
      this.style.backgroundColor = "red";
      selectedRow = this;
  }

  C = R.insertCell()   
  C.innerHTML = "第"+i+"个文件"   
  C = R.insertCell()   
  C.innerHTML = "<input value='123' readOnly ondblclick='b();'>"
    C = R.insertCell()   
  C.innerHTML = "<input value='123' readonly>"  
    C = R.insertCell()   
  C.innerHTML = "<input value='123' readonly>"  
    C = R.insertCell()   
  C.innerHTML = "<input value='123' readonly>"  
    C = R.insertCell()   
  C.innerHTML = "<input value='123' readonly>"  
  C = R.insertCell()   
  C.innerHTML = "项目动态"  
  C = R.insertCell()   
  C.innerHTML = "<input >"  
 }   
 function deleteRow(obj){   
    if(!selectedRow){
        alert("请选择");
    }
   var flag=confirm("请问要确认删除吗?") 
   if(flag){
     // alert(obj.parentElement.parentElement.rowIndex+1);   
        alert(selectedRow.innerHTML);