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 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建