簡體   English   中英

如何從jQuery中的隱藏字段獲取數據? (隱藏字段使用類代替ID)

[英]How can I get the data from hidden field in jQuery? (hidden field has class in place of id)

我正在從數據庫中獲取數據:

<table>
    <?php
    $select_data = mysql_query(" select * from `data_table` ") or die(mysql_error());
    while($data_row = mysql_fetch_array($select_data))
    {
   ?>
   <tr>
      <td> 
         <img src="../Stuff-site_data_images/<?php echo$data_row['data_image_name']?>" width="100" height="100" /> 
      </td>
      <td> <?php echo $data_row['data_image_name'];?> </td>
      <td> <?php echo $data_row['data_description'];?> </td>

我想從這里獲取數據:

      <td align="center" class="row_id">
          <input class="inner_row_id" type="hidden" value="<?php echo $data_row['data_id'];?>" name="show_detail_button" id="show_detail_button"> Show All
      </td>

我想從這里獲取數據:

      </tr>
     <?php
     } 
     ?>
</table>

據我所知,當id超過1時,jQuery將發生沖突,因此這就是為什么我使用CSS類名"row_id" & "inner_row_id" 當我點擊"row_id"我想要的值"inner_row_id"為此,我已經寫了下面的代碼:

        $(".row_id").click(function(e){
            var row_id = $(".inner_row_id").val();
            alert("Le click thyuu....");
        });

有誰建議我該怎么做...

這應該工作

$(".row_id").click(function(e){
  alert($(this).find('.inner_row_id').val()); 
})

“單擊”功能使您可以訪問它,即您單擊的元素。 然后查找查找具有.inner_row_id類的元素的所有后代。

鏈接到jsFiddle

如我所見,您正在動態創建輸入,因此請在JS下面使用:

$(".row_id").on('click',function(e){
  var row_id = $(this).children('.inner_row_id').val();
  alert("Le click thyuu....");
});

演示

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM