Javascript jQuery表映像
编写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
的类并相应地执行操作。该功能通过单击
中的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函数构建对象,以便使用正确的对象 小学生的错误。我也不会发现的,谢谢你!