In javascript-JS, online seat selection has been implemented. How can I select the corresponding seat when I click a seat?

Source: Internet
Author: User
When I select a select time such as A2, the corresponding available and click have been implemented to click the seat. How can I reverse the select statement to click the corresponding seat? {code ...} click the seat and select the corresponding {code ...}

If the select time is set to A2, it corresponds to available and click.
/You have already clicked the seat. How can you click select to select the corresponding seat?/

Var $ cart = $ ('# selected-seats'), $ counter = $ ('# counter'), $ total = $ ('# total '), SC = $ ('# seat-map '). seatCharts ({map: [// seat map 'ff _ ff ', 'ff _ ff', '_____', 'ff _ ff ', 'ff _ ff ', 'ff _ ff'], seats: {// defines the seat attributes f: {price: 100, classes: 'First-class', category: 'First seat '}, e: {price: 40, classes: 'Economy-class', category: 'second-class seat '}, naming: {// top: true, columns: ['A',' B ', 'C', 'D', 'F', 'G'], rows: ['1', '2', '', '3', '4 ', '5', '6', '7', '8', '9'], getLabel: function (character, row, column) {return column + row ;}}, legend: {// defines the legend node: $ ('# legend'), items: [['F', 'available', 'first-class mount'], ['E ', 'available', 'second-class title'], ['F', 'unavailable', 'stopped']}, click: function () {if (this. status () = 'available') {// optional seat $ ('
  • '+ This. data (). category +'
    '+ This. settings. label +'
  • '). Attr ('id', 'cart-item-'+ this. settings. id ). data ('seatid', this. settings. id ). appendTo ($ cart); // Number of votes updated $ counter. text (SC. find ('selected '). length + 1); // calculates the total amount $ total. text (recalculateTotal (SC) + this. data (). price); return 'selected';} else if (this. status () = 'selected') {// $ counter selected. text (SC. find ('selected '). length-1); $ total. text (recalculateTotal (SC)-this. data (). price); // Delete the reserved seat $ ('# cart-item-' + this. settings. id ). remove (); return 'available';} else if (this. status () = 'unavailable') {// sold return 'unavailable';} else {return this. style () ;}, focus: function () {if (this. status () = 'available') {$ ("# seat-info" pai.show().html (this. settings. label + 'number'); Var cd = getMousePoint (event); $ ("# seat-info" ).css ({"left" :( cd. x + 10) + 'px ', "top" :( cd. y-30) + "px"}); return 'focused ';} else {return this. style ();}}});

    /Click the seat and select the corresponding/

    $ (". Available "). on ("click", function () {var txt = $ (this ). text (); // obtain the index of the row where the cursor is located on the current day. It is used to determine whether it is a first-class seat or a second-class seat var index = $ (this ). parent (". seatCharts-row "). index (); // if (index> = 6) {var htmlTxt = "" + txt + "";} else {var htmlTxt = "" + txt + "" ;}$ ("select "). find ("option: selected "). val (txt); $ ("select "). find ("option: selected "). text (htmlTxt );

    Reply content:

    If the select time is set to A2, it corresponds to available and click.
    /You have already clicked the seat. How can you click select to select the corresponding seat?/

    Var $ cart = $ ('# selected-seats'), $ counter = $ ('# counter'), $ total = $ ('# total '), SC = $ ('# seat-map '). seatCharts ({map: [// seat map 'ff _ ff ', 'ff _ ff', '_____', 'ff _ ff ', 'ff _ ff ', 'ff _ ff'], seats: {// defines the seat attributes f: {price: 100, classes: 'First-class', category: 'First seat '}, e: {price: 40, classes: 'Economy-class', category: 'second-class seat '}, naming: {// top: true, columns: ['A',' B ', 'C', 'D', 'F', 'G'], rows: ['1', '2', '', '3', '4 ', '5', '6', '7', '8', '9'], getLabel: function (character, row, column) {return column + row ;}}, legend: {// defines the legend node: $ ('# legend'), items: [['F', 'available', 'first-class mount'], ['E ', 'available', 'second-class title'], ['F', 'unavailable', 'stopped']}, click: function () {if (this. status () = 'available') {// optional seat $ ('
  • '+ This. data (). category +'
    '+ This. settings. label +'
  • '). Attr ('id', 'cart-item-'+ this. settings. id ). data ('seatid', this. settings. id ). appendTo ($ cart); // Number of votes updated $ counter. text (SC. find ('selected '). length + 1); // calculates the total amount $ total. text (recalculateTotal (SC) + this. data (). price); return 'selected';} else if (this. status () = 'selected') {// $ counter selected. text (SC. find ('selected '). length-1); $ total. text (recalculateTotal (SC)-this. data (). price); // Delete the reserved seat $ ('# cart-item-' + this. settings. id ). remove (); return 'available';} else if (this. status () = 'unavailable') {// sold return 'unavailable';} else {return this. style () ;}, focus: function () {if (this. status () = 'available') {$ ("# seat-info" pai.show().html (this. settings. label + 'number'); Var cd = getMousePoint (event); $ ("# seat-info" ).css ({"left" :( cd. x + 10) + 'px ', "top" :( cd. y-30) + "px"}); return 'focused ';} else {return this. style ();}}});

    /Click the seat and select the corresponding/

    $ (". Available "). on ("click", function () {var txt = $ (this ). text (); // obtain the index of the row where the cursor is located on the current day. It is used to determine whether it is a first-class seat or a second-class seat var index = $ (this ). parent (". seatCharts-row "). index (); // if (index> = 6) {var htmlTxt = "" + txt + "";} else {var htmlTxt = "" + txt + "" ;}$ ("select "). find ("option: selected "). val (txt); $ ("select "). find ("option: selected "). text (htmlTxt );

    $ ('Select '). on ('change', function () {var _ this = $ (this); // obtain the selected value here, for example, A4 var seatCode = _ this. find ("option: selected "). val (). split (""); // you do not know what value you put, pretend it is A4 // then you can refer to the array [, 4] switch styles and your own business logic });

    Your HTML and JS Code mixing is very powerful, so the logic is unclear and elasticity is lost. For example, if the user says that I want two second-class seats, it is obvious that your Code cannot be extended. We recommend that you use JS to solve the logic first. As for the display problem, it will be OK later. Example

    Seat list = {'a1': {selected: false; Level: First class; left: false, right: A2, front: false, Back: B1}, 'a2 ': {selected: true, level: 1; left: A1, right: false, front: false, Back: B2 },...}; region list = {: [A1, A2,...], second-class :...}; function isSelectedSeat (x, y) {if (y) x = x + y; return seat list [x]. selected;} function getFreeSeats (lv) {var free = []; foreach seat number from region list. lv {if (isSelectedSeat (seat number) free. push (seat number);} return free;} function setSeatSelected (sites, d IsableSelected) {// set a seat to select/cancel. You can add the return true/false/void for HTML processing here;} function autoSelected (seat level, ticket booking quantity) {// This is troublesome. You need to select an empty seat in the level and try to find the position continuously. If you are kind, you should give priority to the best position, or you can return all the combinations that you can choose from (this is usually used when an operator handles telephone booking ). Var useableSeats = [];... return useableSeats. length? UseableSeats: false ;}

    With the above logic, no matter whether you have a seat or use a drop-down box, setSeatSelected is called for processing, while autoSelected automatically recommends the seat algorithm, after the logic is automatically recommended, you need to ask the user about this location before calling the subsequent processing.

    The above pseudo code is mainly easy to write. You can encapsulate it as an object by yourself, so that if you have multiple places, you only need to instantiate it with appropriate parameters.

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.