doze79040 2015-10-19 07:20
浏览 61

如何通过jQuery获取相同类的所有值,并插入数组并且循环计数在jQuery中不正确?

This is my form

<?php  
        $sql15 = "select * from reviewed_title";
        $query15 = sqlsrv_query( $link, $sql15);
        $count = 1;
        while( $row = sqlsrv_fetch_array( $query15, SQLSRV_FETCH_ASSOC) ) { ?>
        <div class = "title_body">
         <div class = "title_top">
          <div class="form-group">
           <h3><?php 
            $title_id = $row['id'];
            echo $count .".  ".$row['title']; 
            ?>
           </h3>
         </div>
        </div>
        <?php
        $sql16 = "select * from item_reviewed WHERE title_id = $title_id";
                        $count2=1;
         $query16 = sqlsrv_query( $link, $sql16);
         $query17 = sqlsrv_query($link, $sql16, array(), array( "Scrollable" => SQLSRV_CURSOR_KEYSET ));
         $row_num = sqlsrv_num_rows($query17);
            //$row_num = 5;
         while( $row2 = sqlsrv_fetch_array( $query16, SQLSRV_FETCH_ASSOC) ) { ?>    
        <div class = "title_bottom"
        <?php if($row_num != $count2){?> style="border-bottom: 1px solid #000000;" <?php }?> >
            <div class="form-group">
              <input type="hidden" name="item_reviewed_id" value="<?php echo $row2['id'];?>"  class="item_reviewed_id">
                <div class = "title_bottom_left">
                    <h6> <?php echo $count.".".$count2 .".  ".$row2['items']; 
                                ?></h6>
                </div>
                <div class= "title_bottom_center">
                <label class="col-sm-2 label2" for="email">Y,N,N/A:</label>
                                        <!--<select name="action" class="select <select_<?php echo $row2['id'];?>" id="select_<?php echo $count."".$count2;?>">-->
                                        <select name="action" class="select" >
                                          <option value="">Select</option>
                                        <option value="yes">Yes</option>        
                                      </select>
                                  </div>
                <div class ="title_bottom_right">
                <label class="col-sm-2 label3" for="email">Comment:</label>
                    <!--<textarea name="comment" class="form-control comment commentttt comment_<?php echo $row2['id'];?>>"  <id="comment_<?php echo $count."".$count2;?>"   placeholder="Comment"></textarea>-->
                    <textarea name="comment" class="form-control comment commentttt"    placeholder="Comment"></textarea>
                                </div>
                        </div>
                    </div>
                    <?php $count2++;}?>
                </div>
            <?php  $count++; }?>

Here I get 33 input fields, 33 select fields and 33 hidden fields.From table item_reviewed here i get 33 row. My jQuery code is ..

var ittem_id = new Array();
    var j = 1;
    $(".item_reviewed_id" ).each(function( i ) {
        ittem_id[j] = $(this).val();
        j++;
        });
        alert(j);

Here I get 1552 values. How i can get 33 values in jQuery ?

  • 写回答

1条回答 默认 最新

  • doumeitang572461 2015-10-19 08:09
    关注

    if you ve 1552 item and that loop output only 33 rows you must ve some other elements with class .item_reviewed_id in your page. Use 2 classes to be sure you re selecting the right elements. JQuery map could be a very easy way to map your elements values

    <input type="hidden" name="item_reviewed_id" value="<?php echo $row2['id'];?>"  class="item_reviewed_id thisclass">
    
    var ittem_id = $('.item_reviewed_id.thisclass').map(function(){
         return $(this).val();
    });
    
    console.log(ittem_id); //this will be an array with your values!
    
    评论

报告相同问题?

悬赏问题

  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入