weixin_33701294 2017-01-23 08:23 采纳率: 0%
浏览 18

PHP AJAX发布值

how to post value of checkbox when it checked or uncheked

I have Code

    $("#check").click(function(){`var data = {
               kd_material:$("#kd_material").val(),
               check : $(this).val('1') ? $(this).val("1") : $(this).val("0")
              };

   $.ajax({
      type: "POST",
      url : "<?php echo base_url().'ms_select/select_id_material_koreksi_cek'?>",             
      data: data,
      success: function(msg){
         $('#div-gudang').html(msg);
      }
    });
 }); `
  • 写回答

3条回答 默认 最新

  • weixin_33725722 2017-01-23 08:26
    关注

    You can simply use the isChecked property of the checkbox and send it.

    $("#check").click(function(){`var data = {
                       kd_material:$("#kd_material").val(),
                       check : $(this).is(":checked") 
    };
    

    The value true/false would be sent to the server.

    But if you want to send 1/0 you can do it like this.

    check : $(this).is(":checked") ? 1 : 0
    
    评论

报告相同问题?

悬赏问题

  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器