我有以下显示form
的{{1}}:
checkbox
还有我的<form>
<input type="checkbox" class="custom-control-input" id="ch" value="y" required>
<button id="CT" type="button" >Go</button>
</form>
脚本:
AJAX
最后,这是我的<script>
//ST
$('#CT').click(function(){
var fullname = document.getElementById("fn").value;
var username = document.getElementById("un").value;
var emailAdd = document.getElementById("em").value;
var password = document.getElementById("pd").value;
var check = document.getElementById("ch").value;
$.ajax({
type:'POST',url:'ajax/signup.php',
data:'fn='+fullname+'&un='+username+'&em='+emailAdd+'&pd='+password+'&ch='+check,
beforeSend:function(){ $('#WAIT').show(); },
success:function(data){ $('#HERE').html(data); }
});
});
//SD
</script>
脚本:
ajax/signup.php
如何检查<?php
$FN = $_POST["fn"];
$UN = $_POST["un"];
$EM = $_POST["em"];
$PD = $_POST["pd"];
$CH = $_POST["ch"];
if(empty($FN) OR empty($UN) OR empty($EM) OR empty($PD) OR $CH != "y"){
echo""?>
<script>
$("form").addClass("was-validated");
</script>
<?"";
}
?>
是否已在客户端验证?
答案 0 :(得分:0)
如果我正确理解您的问题,那么您正在寻找如何提取复选框的值(作为布尔值)。可以通过如下调用checked
来做到这一点:
var check = document.getElementById("ch").checked;
答案 1 :(得分:0)
使用三元运算符切换ajax的值:
document.getElementById("ch").checked ? 'y' : 'n'