我有一个复选框
<input name="notify" type="checkbox" id="notify" class="notify" />
我正在使用ajax调用
$("form#submit").submit(function() {
// we want to store the values from the form input box, then send via ajax below
var username = $('#username').attr('value');
var email = $('#email').attr('value');
var password = $('#password').attr('value');
var cpassword = $('#cpassword').attr('value');
var notify = $('#notify').attr('value');
var session_user_id = $('#session_user_id').attr('value');
$.ajax({
type: "POST",
url: "../../includes/editprofile.php?",
data: "username="+ username+
"&email="+ email+
"&password="+ password+
"&cpassword="+ cpassword+
"¬ify="+ notify+
"&session_user_id="+ session_user_id,
success: function(data){
$('div.success').fadeIn();
$('div.success').html(data);
}
});
return false;
});
在我的editprofile.php文件中,我只是echo'n $ notify,看看我提交表单后的值是什么,无论是否总是“打开”我是否选中此框。有线索吗?
答案 0 :(得分:3)
所有3应该在
下面工作尝试
$('#notify').is(':checked');
或
$('#notify').attr('checked');
或
$('#notify').prop('checked');
答案 1 :(得分:2)
更改此
var notify = $('#notify').attr('value');
到
var notify = $('#notify').attr('checked');
因为checkbox
没有value
答案 2 :(得分:0)
试试这个
$('#notify').attr('checked') ? "True" : "False";