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