Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery表映像_Javascript_Jquery_Html_Html Table - Fatal编程技术网

Javascript jQuery表映像

Javascript jQuery表映像,javascript,jquery,html,html-table,Javascript,Jquery,Html,Html Table,编写jQuery函数来测试的类并相应地执行操作。该功能通过单击中的img工作,并使用td的类信息进行测试 $(document).ready(function () { $('td img').click(function () { if ((this).parent().hasClass('x')) { alert("Seat " + ((this).parent().attr("id")) + " is taken"); } else if ((this).p

编写jQuery函数来测试
的类并相应地执行操作。该功能通过单击
中的
img
工作,并使用
td
的类信息进行测试

$(document).ready(function () {
$('td img').click(function () {
    if ((this).parent().hasClass('x')) {
        alert("Seat " + ((this).parent().attr("id")) + " is taken");
    } else if ((this).parent().hasClass('selected')){
        $(this).attr('src', 'images/a.gif');
        $(this).parent().removeClass('selected');
        alert($(this).parent().attr("class"));
        return false;
        } else {
        $(this).attr('src', 'images/c.gif');
        $(this).parent().addClass('selected');
        alert($(this).parent().attr("class"));
        return false;
        };
    });
});

错误表明,尽管我指定了父对象,但图像的方法不存在

缺少一个
$
符号

If($(this).parent()...

这里发生的事情是click函数传递dom/html对象,而不是jQuery对象,因此您必须使用jQuery函数构建对象,以便使用正确的对象

小学生的错误。我也不会发现的,谢谢你!