[英]jQuery check checkbox ajax POST output variable to php isset
在提交表单之前,如何检查复选框是否被选中以及是否输出回php。 我知道可以使用jQuery和is(':checked')以及可能的Ajax POST来检查复选框状态。
我已经搜索过,但是没有找到我想要的东西。
confirmation.php
<script>
$(function() {
if ($('#noemail').attr('checked')) {
$.ajax({
type: "POST",
data: "noemail=1",
url: "confirmation.php",
success: function(msg) {
alert("wowwww... checked");
}
});
}
});
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<input name="noemail" id="noemail" checked="checked" type="checkbox">
<?php
if((isset($_GET['noemail'])&&($_GET['noemail'] == '1')){
session_register('noemail');
}
?>
我需要将以下内容返回到confirmation.php,这是在php中进行注册的功能。
session_register('noemail');
而不是警报消息,我需要一个ajax url POST来设置一个变量,可以使用isset在php中检查该变量,如果使用该变量可以激活该功能。
检查是否使用JavaScript选中了一个复选框:
HTML档案:
<input name="noemail" id="noemail" type="checkbox" id="myCheck" onclick="myFunction()">
<p id="text" style="display:none">Checkbox is CHECKED!</p>
JavaSccript:
function myFunction() {
// Get the checkbox
var checkBox = document.getElementById("myCheck");
// Get the output text
var text = document.getElementById("text");
// If the checkbox is checked, display the output text
if (checkBox.checked == true){
text.style.display = "block";
} else {
text.style.display = "none";
}
}
好的,有时候事情很复杂,有时候不是,但是jQuery是写更少的代码……如口号所示:写更少,做更多……无论如何这是一个示例,我希望可以帮助@wolfen理解并解决问题正是他/她需要的。
$(function() { if ($('#noemail').attr('checked')) { alert("wowwww... checked"); // do what you want or need } });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <input name="noemail" id="noemail" checked="checked" type="checkbox">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.