我希望获得类似http://example.com/mymovieSeatBook.html?booking=0-0> 0-1的网址输出,但我的示例显示http://example.com/mymovieSeatBook.html?booking=0-3仅表示li href值的第一个值 当我选择0-0行和0-1行
时<button id="click">Submit</button>
var init = function (Seat) {
var str = [], seatNo, className;
var rows= Seat.length;
var cols= Seat[0].length;
for (i = 0; i <rows; i++) {
for (j = 0; j <cols; j++) {
seatNo = (i + j *rows + 1);
className = settings.seatCss + ' ' + settings.rowCssPrefix + i.toString() + ' ' + settings.colCssPrefix + j.toString();
if (Seat[i][j]==settings.reservedSeat) {
className += ' ' + settings.selectedSeatCss;
//console.log(inArray(seatNo, reservedSeat));
}
else if(Seat[i][j]== settings.unavilableSeat){
className += ' ' + settings.unavaliableSeatCss;
//console.log(settings.unavaliableSeatCss);
}
str.push('<li title="'+seatNo+'" class="' + className + '"' +
'style="top:' + (i * settings.seatHeight).toString() + 'px;left:' + (j * settings.seatWidth).toString() + 'px" href="'+i,'-',j+'">' +
'<a title="' + seatNo + '">' + seatNo + '</a>' +
'</li>');
}
}
$('#place').html(str.join(''));
};
//case I: Show from starting
//init();
//Case II: If already booked
var Seats =[ [ 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0 ,0 , 0],
[ 2, 2, 2, 2 ,2, 0],
[ 3, 3, 3, 3 ,3, 0],
];
init(Seats);
var clickNum=0;
$('.' + settings.seatCss).on('click',function () {
if ($(this).hasClass(settings.selectedSeatCss)){
alert('This seat is already reserved');
}
else if($(this).hasClass(settings.unavaliableSeatCss))
{
alert('Sorry!!!This is unavailable Seats');
}
else
{
if($(this).hasClass(settings.selectingSeatCss))
{
$(this).removeClass(settings.selectingSeatCss);
var SeatNo=$(this).closest("li").attr("title");
$(".sitting:last").remove();
}
else
{
$(this).addClass(settings.selectingSeatCss);
var link=$(this).attr('href');
link=link+"";
var SeatNo=$(this).closest("li").attr("title");
// console.log(traverse.closest("a"));
//var SeatNo=$(this).closest("a").attr("title");
$('<div class="sitting" title="'+SeatNo+'">SeatNo:>'+SeatNo+ '</div>').appendTo('#order_place');
}
}
});
$("#click").click(function(){
var his=$('li.selectingSeat').attr("href");
window.history.pushState({push:this.push},'','?booking='+his);//Here it taking only previous value
});
});
这里我的代码只采用了selectionSeat的先前值。我希望得到所有选定的座位值,并以这种方式说0-0&gt; 0-1&gt; 0-6
答案 0 :(得分:0)
这可以通过
完成 var realvalues = [];
$('li.selectingSeat').each(function(i){realvalues[i]=$(this).attr("href");});
realvalues=realvalues.join('>');
window.history.pushState({push:this.push},'','?booking='+realvalues);