如何在动态表中检索输入类型的值 [英] How to retrieve value of input type in a dynamic table

查看:93
本文介绍了如何在动态表中检索输入类型的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我有一个表格,像这样

 < table border =1id =dataTable> ; 
< tr>
< td>
<强>文字< / strong>
< / td>
< td>
< Strong>字体< / strong>
< / td>
< td>
< Strong>大小< / strong>
< / td>
< td>
< Strong>颜色< / strong>
< / td>
< tr>
< td>
< input type =Text>
< / td>
< td>
< input type =Text>
< / td>
< td>
< input type =Text>
< / td>
< td>
< input type =Text>
< / td>
< / tr>
< / tr>
< / table>
< INPUT type =buttonvalue =添加行onclick =addRow('dataTable')/>
< INPUT type =buttonvalue =Delete Rowonclick =deleteRow('dataTable')/>
< INPUT type =buttonvalue =Showonclick =showContent('dataTable')/>

我已经设置了JavaScript,所以我可以添加一行,删除可以正常工作的行,但我在尝试获取输入类型内部的值时遇到了实际问题。



以下是我尝试获取其中一个值的代码

  function showContent(tableID){
var tbl = document.getElementById(tableID);
var rCount = tbl.rows.length;
尝试{
alert(tbl.rows [rCount - 1] .cells [0] .innerHTML);

} catch(e){
alert(e);
}

}

然而,警报框刚刚出现with:

 < input type =Text> 

我想要检索输入框内的实际值。谁能告诉我我做错了什么?



在此先感谢。 试图访问该值...

$ p $ alert(tbl.rows [rCount-1] .cells [0] .children [ 0]。价值);


Okay I have a table set out like this

 <table border="1" id="dataTable">
   <tr>
      <td>
          <Strong>Text</Strong>
      </td>
      <td>
          <Strong>Font</Strong>
      </td>
      <td>
          <Strong>Size</Strong>
      </td>
      <td>
          <Strong>Color</Strong>
      </td>
      <tr>
      <td>
          <input type="Text">
      </td>
      <td>
           <input type="Text">
      </td>
      <td>
            <input type="Text">
      </td>
      <td>
            <input type="Text">
      </td>
    </tr>
   </tr>
 </table>
 <INPUT type="button" value="Add Row" onclick="addRow('dataTable')" />
 <INPUT type="button" value="Delete Row" onclick="deleteRow('dataTable')" />       
 <INPUT type="button" value="Show" onclick="showContent('dataTable')" />

I have the JavaScript set up so I can add a row, delete a row which works fine, but I am having real problems trying to get the value of what is inside the input type.

Here is the code I tried to get one of the values

  function showContent(tableID) {
     var tbl = document.getElementById(tableID);
     var rCount = tbl.rows.length;
     try {
         alert(tbl.rows[rCount - 1].cells[0].innerHTML);

     } catch (e) {
         alert(e);
     }

 }

However the alert box just comes up with:

 <input type="Text">

I want to retrieve the actual value of what's inside the input box. Could anyone tell me what I am doing wrong?

Thanks in advance.

解决方案

Well you're not even trying to access the value...

alert(tbl.rows[rCount-1].cells[0].children[0].value);

这篇关于如何在动态表中检索输入类型的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆