douxie2029
2018-09-09 23:30
浏览 39
已采纳

如果在ajax中选中了复选框,该怎么读?

I have the following form which displays a checkbox:

<form>
    <input type="checkbox" class="custom-control-input" id="ch" value="y" required>
    <button id="CT" type="button" >Go</button>
</form>

And my AJAX script:

<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>

Lastly, here is my ajax/signup.php script:

<?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>
    <?"";
}
?>

How to check if the checkbox was validated on the client side?

2条回答 默认 最新

相关推荐 更多相似问题