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 u盘问题:盘符不显示 无媒体
  • ¥50 R语言读取nc按月均值转为tif
  • ¥30 智能车串级pid调参
  • ¥15 visual studio code翻译老是错误
  • ¥20 卫星测高数据的高程转换
  • ¥15 爬取招聘网站数据信息
  • ¥15 安装完tensorflow,import tensorflow as tf后报错,如何解决?
  • ¥15 ultralytics库导出onnx模型,模型失去预测能力
  • ¥15 linux下点对点协议连接2个USB串口的硬件流量控制问题
  • ¥15 SQL数据自动生成问题