switch statement in Jquery and List

前端 未结 4 828
余生分开走
余生分开走 2020-12-16 23:03

I would like to know if my approach is efficient and correct. my code is not working though, I don\'t know why.



        
4条回答
  •  -上瘾入骨i
    2020-12-16 23:45

    Several problems.

    1) There is no need for the function to be within $(document).ready, get rid of that.


    2) Every case statement should be followed by a break, not a lone ;. For example:

    function HotelQuery(HotelName) {
        switch (HotelName) {
        case 'TetrisHotel': 
            // stuff goes here ...  
            break; //end Tetris Hotel 
        };
    }
    

    3) alert shouldn't be followed by a : in your onclick handler:

    alert: (strHotelName, strHotelDesc, strHotelPrice);
    

    should be

    alert(strHotelName, strHotelDesc, strHotelPrice);
    

    Also, alert only takes one parameter, so you need to break it up:

    alert(strHotelName); alert(strHotelDesc); alert(strHotelPrice);
    

    3) You're assuming strHotelName, strHotelDesc and strHotelPrice are in the global scope, which they are not.


    Altogether, you might want to try something like this:

    
    
    
    
     
    
          
    
    hotel query
    
    
    
      Tetris Hotel Query
      

提交回复
热议问题