dt3358 2013-10-26 17:04
浏览 43
已采纳

Jquery点击不触发

I am using a while loop to create a table and I am trying to pass a unique value stored in a php variable called $i to a jquery ajax call but all I get returned it 'undefined'.

The portion of the html table (whole table is wrapped in a div called audit_content which is not part of the while loop)

  <tr>
      <td colspan="3">
          <input type="button" class="delete_submit delete_from_audit" name="image_delete" value="" 
               onClick="delete_image('<? echo $image_id; ?>','<? echo $audit_id; ?>')" />
          <input type="button" class="reset_grade control_submit ie7_reset" 
               onclick="reset_image('<? echo $image_id; ?>','<? echo $audit_id; ?>')" value="" >
          <input type="hidden" class="form_id" value="<? echo $i; ?>" >
          <input type="button" name="audit_submit"
            class="audit_submit audit_submit_btn ie7_submit" value=""; />
      </td>
  </tr> 

the Jquery

<script>
  $(document).ready(function(){
    $('#audit_content').on("click", ".audit_submit", function(){
        var form_id = $(this).next('.form_id').val();
        alert(form_id);
           //$.ajax({
           //type: "POST",
           //url: "ajax/image_audit.php",
           //data: $('#audit_form').serialize()
        //});
    });
});
</script>
  • 写回答

3条回答 默认 最新

  • dongmoxin7111 2013-10-26 17:06
    关注

    The .form_id element is before the .audit_submit button... Try prev() instead of next():

    var form_id = $(this).prev('.form_id').val();
    

    You could also use siblings():

    var form_id = $(this).siblings('.form_id').val();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 Stata链式中介效应代码修改
  • ¥15 latex投稿显示click download
  • ¥15 请问读取环境变量文件失败是什么原因?
  • ¥15 在若依框架下实现人脸识别
  • ¥15 网络科学导论,网络控制
  • ¥100 安卓tv程序连接SQLSERVER2008问题
  • ¥15 利用Sentinel-2和Landsat8做一个水库的长时序NDVI的对比,为什么Snetinel-2计算的结果最小值特别小,而Lansat8就很平均
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错