【问题标题】:How to get some value of TD inside some TR with jquery如何使用 jquery 在一些 TR 中获取 TD 的一些值
【发布时间】:2012-03-06 22:27:45
【问题描述】:

我有一个表,其中每一行都有一个与该行关联的复选框(同名)。所以我想让用户选择一个或多个复选框并将其删除。问题是行属于两类信息。所以我有类名1 的行和类名2 的行。这是我到目前为止开发的代码:

function delete() {
    // here i take all the checkbox checked
    var checked = $("input[type=checkbox]:checked");
    // the number of checkbox checked
    var nbChecked = checked.size();
    // just to the dialog
    var b = nbChecked == 1 ? "notification" : "notifications";
    if (confirm('Are you sure to delete [' + nbChecked + '] ' + b + "?\nTake care.. you cannot resume the action!")) {
        if (nbChecked > 1) {
            // i want to generate a matrix. every row has an array of information.
            var arr1;
            // i take this code on web, but it doesn't work. I want to pur in sent all 
            // the tr with class sent and with input checkbox associated with it checked.    
            var sent = $('.mainTable').find("tr.sent input[type=checkbox]:checked").get();
            //HERE i want to iterate array sent to take all the information of td inside it and pur in arr1.
            //HERE THE SAME DONE STILL NOW BUT CHANGING TR CLASS              
        } else {
            // HERE IS SIMPLE
        }
    }
}​

编辑: 这是classname为sent的那一行:

<TR valign=top name="rowSent1" style="background-color: #33CCCC" class="sent">
   <input type="hidden" value="messageRowSent1" name="message"/>
   <TD width=12>
      <div class="wpmd">
         <div align=center>
        <font color="#FF0000" class="ws7">
           <input type="checkbox" name="rowSent1" onchange="analizeCheckBox()"/> // onchange to check inputs checked
     </div>
      </div>
   </TD>
   <TD width=147 >
      <div class="wpmd">
         <div align=center>
        <font color="#000000" class="ws7"><I><div class="info1">info1</div></I></font>
     </div>
      </div>
   </TD>
   <TD width=156 >
      <div class="wpmd">
         <div align=center>
            <font color="#000000" class="ws7"><I><div class="info2">info2</div></I></font>
         </div>
      </div>
   </TD>
</TR>

然后我有其他行具有相同的类和其他行具有另一个类名。

你能帮帮我吗?谢谢!!!!

【问题讨论】:

  • 你能把你的表格的 HTML 贴出来吗?
  • 当然!一会儿
  • 在 jquery 中我只需要获取信息以通过 post 传递到 php 页面。我想将矩阵传递给 php 页面以对其进行迭代并进行正确的查询。
  • @RoryMcCrossan 没有想法?

标签: jquery jquery-selectors checkbox tablerow


【解决方案1】:

我做了这个,它的工作:

function getMatrix(type){
                var array;
               if(type=="sent"){
                  array = $("tr.sent input[type=checkbox]:checked").toArray()
               }else{
                  array = $("tr.period input[type=checkbox]:checked").toArray()
               }
                        var total = new Array();
                        for(var i=0;i<array.length;i++){
                            var tds = $(array[i]).parents("tr").children('td').toArray();
                            var mess = $(array[i]).parents("tr").children('input[type=hidden]').val();
                            var middle = new Array();
                            middle.push(mess);
                            for(var j=0;j<tds.length;j++){
                                var ii = $(tds[j]).text();
                                middle.push($.trim(ii));
                            }
                            total.push(middle);
                        }
                        return total;   
            }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-10-04
    • 2015-08-16
    • 2021-10-03
    • 1970-01-01
    • 2017-06-21
    • 2016-01-24
    • 2019-06-13
    • 1970-01-01
    相关资源
    最近更新 更多