1
我目前正在设计一个使用javascript,html和css的网页。该页面是座位预订座位,允许用户选择和取消选择座位。当用户选择座位时,我设法让页面显示座位的ID,但是如果用户取消选择座位,我在尝试从显示中删除ID时遇到问题。附加并删除元素
下面是JavaScript代码
$('.available, .unavailable, .selected').click(function(){
var ID = $(this).attr('class');
if (ID == 'n unavailable' || ID == 'p unavailable') {
alert ('Seat is already booked. Please select another seat.');
}
else if (ID == 'n selected' || ID == 'p selected') {
alert ('You have now unselected this seat.');
$(this).html('<img src = "free.gif"/>');
$(this).removeClass('selected').addClass('available');
y--;
$("#seats").html("Number of seats selected: " + y);
$("#list").remove($(this).attr('id'));
}
else {
alert ('You have now reserved this seat. You can unselect it by clicking the seat again.');
$(this).html('<img src = "selected.gif"/>');
$(this).removeClass('available').addClass('selected');
y++;
$("#seats").html("Number of seats selected: " + y);
$("#list").append($(this).attr('id') + "</br>");
}
});
什么是'$( '#list')'?它是一个显示所选座位ID的'div'或'span'吗? – Marcus 2013-02-19 21:23:00