0

我想获得像http://example.com/mymovieSeatBook.html?booking=0-0 >0-1 这样的 url 输出,但我的示例显示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>0-1>0-6 的形式

4

1 回答 1

0

这可以通过

   var realvalues = [];

$('li.selectingSeat').each(function(i){realvalues[i]=$(this).attr("href");});
            realvalues=realvalues.join('>');



             window.history.pushState({push:this.push},'','?booking='+realvalues);
于 2012-07-10T17:43:59.323 回答