我目前正在使用 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>");
}
});