[英]PHP AJAX POST VALUE
選中或取消選中復選框時如何發布其值
我有密碼
$("#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);
}
});
}); `
$(this).val('1')
不返回布爾值。 它將$(this)
的值設置為1
並返回$(this)
進行鏈接。
要判斷該框是否已選中,請使用this.checked
或$(this).is(":checked")
this.checked
$(this).is(":checked")
。 因此應該是:
check: this.checked ? 1 : 0
您可以簡單地使用復選框的isChecked屬性並將其發送。
$("#check").click(function(){`var data = {
kd_material:$("#kd_material").val(),
check : $(this).is(":checked")
};
值true / false將發送到服務器。
但是,如果您要發送1/0,則可以這樣做。
check : $(this).is(":checked") ? 1 : 0
嘗試這個:
$("#check").click(function(){
if($(this).is(':cheked'))
{
var chkValue = 1;
}
else
{
var chkValue = 0;
}
});
將chkValue用作ajax() data
的變量,例如:
data: {
value : chkValue
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.