CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Web 开发 >  JavaScript

100分求助两个菜鸟问题:关于table的问题!!!!!

楼主xgp1226()2004-04-04 16:22:40 在 Web 开发 / JavaScript 提问

 
  1、怎样向一个table中的任意行后添加一行?(不是在table的最后一行后添加一行。)  
   
  2、table中的单元格中有一个textbox,当点击页面中的一个button时,把单元格中的textbox删除。  
   
   
  请高手帮我实现以上两个功能!  
   
  万分感谢! 问题点数:100、回复次数:7Top

1 楼ice_berg16(寻梦的稻草人)回复于 2004-04-04 16:30:02 得分 20

2.  
  <input   type=button   onclick="document.all.textbox.innerHTML=''">  
  <table>  
  <tr>  
  <td   id=textbox><input   type=text   value=aaa></td>  
  </tr>  
  </table>Top

2 楼LxcJie(肖冲*爱*捷捷)回复于 2004-04-04 17:03:34 得分 20

<HTML>  
  <HEAD>  
  <META   http-equiv="Content-Type"   content="text/html;   charset=gb2312">  
  <SCRIPT   language="javascript">  
  function   insRow(index)  
  {  
  var   oTr   =   document.all.table1.insertRow(index);  
  for(var   i=0;   i<document.all.table1.rows[1].cells.length;   i++)  
  {  
  var   oTd   =   oTr.insertCell(i);  
  oTd.innerText   =   i;  
  }  
  }  
  function   clearTd()  
  {  
  document.all.td1.innerHTML   =   "&nbsp";  
  }  
   
  </SCRIPT>  
  </HEAD>  
   
  <BODY>  
  <TABLE   id="table1"   width="200"   border="1">  
      <TR>  
          <TD>b</TD>  
          <TD>b</TD>  
          <TD>b</TD>  
          <TD>b</TD>  
      </TR>  
      <TR>  
          <TD>b</TD>  
          <TD>b</TD>  
          <TD>b</TD>  
          <TD>b</TD>  
      </TR>  
      <TR>  
          <TD>v</TD>  
          <TD>v</TD>  
          <TD>v</TD>  
          <TD>v</TD>  
      </TR>  
      <TR>  
          <TD   id="td1"><INPUT   value="aaa"></TD>  
          <TD>f</TD>  
          <TD>f</TD>  
          <TD>f</TD>  
      </TR>  
  </TABLE>  
  <INPUT   type="button"   value="insert"   onClick="insRow(2)">  
  <INPUT   type="button"   value="clear"   onClick="clearTd()">  
  </BODY>  
  </HTML>  
  Top

3 楼wanghr100(灰豆宝宝.net(努力工作))回复于 2004-04-04 18:24:38 得分 20

1.  
   
  <table   id=tb>  
  <tr><td>Cell1</td></tr>  
  <tr><td>Cell3</td></tr>  
  </table>  
  <input   type=button   onclick="addRow(1)"   value="addRow">  
  <script>  
  function   addRow(s)  
  {    
        //参数s,插入到成为第几行,0开始  
        var   tr1   =   tb.insertRow(s);  
        var   td1   =   tr1.insertCell();  
        td1.innerText   ="Cell2";  
  }  
  </script>Top

4 楼wanghr100(灰豆宝宝.net(努力工作))回复于 2004-04-04 18:29:49 得分 0

2.  
   
  <table   id=tb>  
  <tr><td>Cell1</td></tr>  
  <tr><td><input   type=text   id=txt   value="ttt"></td></tr>  
  </table>  
  <input   type=button   onclick="delText('txt')"   value="delText">  
  <script>  
  function   delText(element)  
  {  
          //参数element,   Text的ID  
          eval(element+".outerHTML=''")  
  }  
  </script>Top

5 楼InternetEmail(影子)回复于 2004-04-11 10:28:47 得分 20

function   addRow(rowIndex)  
  {    
        var   table   =   document.all("tableId");  
        var   newRow   =   table.insertRow(rowIndex);  
        newCell=newRow.insertCell();  
  }  
   
  ================================================================  
   
  function   deleteTextbox()  
  {  
        var   table   =   document.all("tableId");  
        table.rows(rowIndex).cells[cellIndex].innerHTML   =   "";  
  }Top

6 楼afoskoo(暂停打印)回复于 2004-04-11 10:50:32 得分 20

<HTML>  
  <HEAD>  
  <TITLE>Modifying   Table   Cell   Content</TITLE>  
  <STYLE   TYPE="text/css">  
  THEAD   {background-color:lightyellow;   font-weight:bold}  
  TFOOT   {background-color:lightgreen;   font-weight:bold}  
  #myTABLE   {background-color:bisque}  
  </STYLE>  
   
  <SCRIPT   LANGUAGE="JavaScript">  
  var   theTable,   theTableBody  
  function   init()   {  
  theTable   =   (document.all)   ?   document.all.myTABLE   :   document.getElementById("myTABLE")  
  theTableBody   =   theTable.tBodies[0]  
  }  
  function   appendRow(form)   {  
  insertTableRow(form,   -1)  
  }  
   
  function   addRow(form)   {  
  insertTableRow(form,   form.insertIndex.value)  
  }  
   
  function   insertTableRow(form,   where)   {  
  var   now   =   new   Date()  
  var   nowData   =   [now.getHours(),   now.getMinutes(),   now.getSeconds(),   now.getMilliseconds()]  
  clearBGColors()  
  var   newCell  
  var   newRow   =   theTableBody.insertRow(where)  
  for   (var   i   =   0;   i   <   nowData.length;   i++)   {  
  newCell   =   newRow.insertCell(i)  
  newCell.innerHTML   =   nowData[i]  
  newCell.style.backgroundColor   =   "salmon"  
  }  
  updateRowCounters(form)  
  }  
   
  function   removeRow(form)   {  
  theTableBody.deleteRow(form.deleteIndex.value)  
  updateRowCounters(form)  
  }  
   
  function   insertTHEAD(form)   {  
  var   THEADData   =   ["Hours","Minutes","Seconds","Milliseconds"]  
  var   newCell  
  var   newTHEAD   =   theTable.createTHead()  
  newTHEAD.id   =   "myTHEAD"  
  var   newRow   =   newTHEAD.insertRow(-1)  
  for   (var   i   =   0;   i   <   THEADData.length;   i++)   {  
  newCell   =   newRow.insertCell(i)  
  newCell.innerHTML   =   THEADData[i]  
  }  
  updateRowCounters(form)  
  form.addTHEAD.disabled   =   true  
  form.deleteTHEAD.disabled   =   false  
  }  
   
  function   removeTHEAD(form)   {  
  theTable.deleteTHead()  
  updateRowCounters(form)  
  form.addTHEAD.disabled   =   false  
  form.deleteTHEAD.disabled   =   true  
  }  
   
  function   insertTFOOT(form)   {  
  var   TFOOTData   =   ["Hours","Minutes","Seconds","Milliseconds"]  
  var   newCell  
  var   newTFOOT   =   theTable.createTFoot()  
  newTFOOT.id   =   "myTFOOT"  
  var   newRow   =   newTFOOT.insertRow(-1)  
  for   (var   i   =   0;   i   <   TFOOTData.length;   i++)   {  
  newCell   =   newRow.insertCell(i)  
  newCell.innerHTML   =   TFOOTData[i]  
  }  
  updateRowCounters(form)  
  form.addTFOOT.disabled   =   true  
  form.deleteTFOOT.disabled   =   false  
  }  
   
  function   removeTFOOT(form)   {  
  theTable.deleteTFoot()  
  updateRowCounters(form)  
  form.addTFOOT.disabled   =   false  
  form.deleteTFOOT.disabled   =   true  
  }  
   
  function   insertCaption(form)   {  
  var   captionData   =   form.captionText.value  
  var   newCaption   =   theTable.createCaption()  
  newCaption.innerHTML   =   captionData  
  form.addCaption.disabled   =   true  
  form.deleteCaption.disabled   =   false  
  }  
   
  function   removeCaption(form)   {  
  theTable.deleteCaption()  
  form.addCaption.disabled   =   false  
  form.deleteCaption.disabled   =   true  
  }  
   
  //   housekeeping   functions  
  function   updateRowCounters(form)   {  
  var   sel1   =   form.insertIndex  
  var   sel2   =   form.deleteIndex  
  sel1.options.length   =   0  
  sel2.options.length   =   0  
  for   (var   i   =   0;   i   <   theTableBody.rows.length;   i++)   {  
  sel1.options[i]   =   new   Option(i,   i)  
  sel2.options[i]   =   new   Option(i,   i)  
  }  
  form.removeRowBtn.disabled   =   (i==0)  
  }  
   
  function   clearBGColors()   {  
  for   (var   i   =   0;   i   <   theTableBody.rows.length;   i++)   {  
  for   (var   j   =   0;   j   <   theTableBody.rows[i].cells.length;   j++)   {  
  theTableBody.rows[i].cells[j].style.backgroundColor   =   ""  
  }  
  }  
  }  
   
  </SCRIPT>  
  </HEAD>  
   
  <BODY   onLoad="init()">  
  <H1>Modifying   Tables</H1>  
  <HR>  
  <FORM   NAME="controls">  
  <FIELDSET>  
  <LEGEND>Add/Remove   Rows</LEGEND>  
  <TABLE   WIDTH="100%"   CELLSPACING=20><TR>  
  <TD><INPUT   TYPE="button"   VALUE="Append   1   Row"   onClick="appendRow(this.form)"></TD>  
  <TD><INPUT   TYPE="button"   VALUE="Insert   1   Row"   onClick="addRow(this.form)">   at   index:    
  <SELECT   NAME="insertIndex">  
  <OPTION   VALUE="0">0  
  </SELECT></TD>  
  <TD><INPUT   TYPE="button"   NAME="removeRowBtn"   VALUE="Delete   1   Row"   DISABLED   onClick="removeRow(this.form)">   at   index:    
  <SELECT   NAME="deleteIndex">  
  <OPTION   VALUE="0">0  
  </SELECT></TD>  
  </TR>  
  </TABLE>  
  </FIELDSET>  
  <FIELDSET>  
  <LEGEND>Add/Remove   THEAD   and   TFOOT</LEGEND>  
  <TABLE   WIDTH="100%"   CELLSPACING=20><TR>  
  <TD><INPUT   TYPE="button"   NAME="addTHEAD"   VALUE="Insert   THEAD"   onClick="insertTHEAD(this.form)"><BR>  
  <INPUT   TYPE="button"   NAME="deleteTHEAD"   VALUE="Remove   THEAD"   DISABLED   onClick="removeTHEAD(this.form)">  
  </TD>  
  <TD><INPUT   TYPE="button"   NAME="addTFOOT"   VALUE="Insert   TFOOT"   onClick="insertTFOOT(this.form)"><BR>  
  <INPUT   TYPE="button"   NAME="deleteTFOOT"   VALUE="Remove   TFOOT"   DISABLED   onClick="removeTFOOT(this.form)">  
  </TD>  
  </TR>  
  </TABLE>  
  </FIELDSET>  
  <FIELDSET>  
  <LEGEND>Add/Remove   Caption</LEGEND>  
  <TABLE   WIDTH="100%"   CELLSPACING=20><TR>  
  <TD><INPUT   TYPE="button"   NAME="addCaption"   VALUE="Add   Caption"   onClick="insertCaption(this.form)"></TD>  
  <TD>Text:   <INPUT   TYPE="text"   NAME="captionText"   SIZE=40   VALUE="Sample   Caption">  
  <TD><INPUT   TYPE="button"   NAME="deleteCaption"   VALUE="Delete   Caption"   DISABLED   onClick="removeCaption(this.form)"></TD>  
  </TR>  
  </TABLE>  
  </FIELDSET>  
  </FORM>  
  <HR>  
  <TABLE   ID="myTABLE"   CELLPADDING=10   BORDER=1>  
  <TBODY>  
  </TABLE>  
  </BODY>  
  </HTML>  
  Top

7 楼tqhchina(spck)回复于 2004-04-24 22:47:05 得分 0

upTop

相关问题

  • 菜鸟张嘴(Table is busy ~~~~~~~)
  • 有关checkbox和table的菜鸟问题!~~
  • 怎么替换</table>,菜鸟求解
  • 菜鸟两问
  • 菜鸟三两问???
  • 菜鸟问题:怎样在后台调用table的Cssclass
  • 菜鸟问题:Table 读取数据库数据的问题
  • 菜鸟
  • 菜鸟
  • 菜鸟

关键词

  • modifying tables
  • remove
  • add

得分解答快速导航

  • 帖主:xgp1226
  • ice_berg16
  • LxcJie
  • wanghr100
  • InternetEmail
  • afoskoo

相关链接

  • Web开发类图书

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo