現在、javascript、html、css を使用して Web ページをデザインしています。このページは、ユーザーが座席を選択および選択解除できる座席予約シートです。ユーザーが座席を選択したときにページに座席の 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>");
}
});