如何遍历表单元格与jQuery和发送数据到数据库遍历、表单、数据库、数据

由网友(没媳妇重要i)分享简介:什么是通过一台循环,抢占了所有数据的单元格,但跳过&LT的最佳方法;第i个?难道我把数据在阵列?What's the best method for looping through a table, grabbing all the data in the cells, but skipping the ?...

什么是通过一台循环,抢占了所有数据的单元格,但跳过&LT的最佳方法;第i个?难道我把数据在阵列?

What's the best method for looping through a table, grabbing all the data in the cells, but skipping the <th>? Do I put the data in an array?

推荐答案

假设你有一个看起来像这样的表:

Say you have a table that looks like this:

<table>
    <tr>
        <td>Information 1</td>
        <td>Information 2</td>
    </tr>
</table>

您可以做这样的事情:

var cells = new Array();
$("table td").each(function(){
   cells.push($(this).html());
});

究竟是什么,你希望做与数据?

What exactly are you looking to do with the data?

最简单的事情做跳过头从数组中循环完成后,将只删除它们。

The easiest thing to do to skip the headers would to just remove them from the array after the loop is done.

在code完成后,您可以运行这样的:

After the code is done, you can run something like this:

细胞= cells.slice(1,cells.length);

cells = cells.slice(1, cells.length);

这将设置阵列自身的副本,减去第一个元素。

This will set the array to a copy of itself, minus the first element.

或者,在最初通过它循环,只有存储的信息,如果该指数大于零:

Alternatively, when you initially loop through it, only store the information if the index is greater than zero:

var cells = new Array();
$("table td").each(function(index){
   if(index > 0){
      cells.push($(this).html());
   }
});

最后,如果你想去一个更传统的JavaScript的解决方案,并不需要一个条件:

And finally, if you'd like to go with a more traditional javascript solution that does not require a condition:

var cells = new Array();
for(index = 1; index < $("table td").length; index++){
   cells.push($("table td").get(index).html());
};

这样的话,你就从第二排开始。

That way, you're starting from the second row.

阅读全文

相关推荐

最新文章