Php 如果用户更改复选框值,JQuery复选框将显示警报

Php 如果用户更改复选框值,JQuery复选框将显示警报,php,jquery,forms,checkbox,nested-if,Php,Jquery,Forms,Checkbox,Nested If,基本上,我有一个表单,可以显示mysql数据库中的一组动态复选框——这很好用。我有一个名为default的属性,我将mysql条目的值放入其中,以便稍后我可以确定用户是否更改了最初显示的复选框值。以下是生成这些复选框的while语句的一部分: printf("\t<tr class='recordrow'> \n\t\t<td><a class='page_modal' href='#mWindow%s' target='_blank'>%s&

基本上,我有一个表单,可以显示mysql数据库中的一组动态复选框——这很好用。我有一个名为default的属性,我将mysql条目的值放入其中,以便稍后我可以确定用户是否更改了最初显示的复选框值。以下是生成这些复选框的while语句的一部分:

printf("\t<tr class='recordrow'>
        \n\t\t<td><a class='page_modal' href='#mWindow%s' target='_blank'>%s</a></td>
        \n\t\t<td class='ppath'>%s</a></td>
        \n\t\t<td>%s</td>
        \n\t\t<td><input type='checkbox' class='checkbox' name='$page_path current' default='$currentcheckbox' $currentcheckbox/><div class='page_dialog' id='mWindow%s'><img src='exit.png' class='close' alt='close'/><img src='newwin.jpg' alt='new window'/><div id='content_section'>%s</div></div> </td>
        \n\t\t<td><input type='checkbox' class='checkbox' name='$page_path prospective' default='$prospectivecheckbox' $prospectivecheckbox/></td>
        \n\t\t<td><input type='checkbox' class='checkbox' name='$page_path faculty' default='$facultycheckbox' $facultycheckbox/></td>
        \n\t\t<td><input type='checkbox' class='checkbox' name='$page_path staff' default='$staffcheckbox' $staffcheckbox/></td>
        \n\t\t<td><input type='checkbox' class='checkbox' name='$page_path external' default='$externalcheckbox' $externalcheckbox/></td>
当我选中和取消选中复选框时,我在我的chrome开发工具中遇到此错误:
未捕获的TypeError:对象0没有方法“val”

$this.attrdefault返回包含属性值的字符串。不用调用.val就可以单独使用它。

试着使用.text。谢谢,我还是JQuery的初学者,它修复了我的错误,现在我看到了我的提醒。
$(document).ready(function() {
$('.checkbox').change(function() {
    if($(this).is(":checked")) {
        var returnVal = confirm("checked");
        if($(this).attr("default").val() != returnVal)
        {
            alert("Value is different from original");
            //put element in changed item array
        }
    }
    else{
        var returnVal = confirm("unchecked");
        var returnVal = "0";
        if($(this).attr("default").val() != returnVal)
        {
            alert("Value is different from original");
            //put element in changed item array
        }
    }
});