<tfoot id='rOeg7'></tfoot>
  1. <i id='rOeg7'><tr id='rOeg7'><dt id='rOeg7'><q id='rOeg7'><span id='rOeg7'><b id='rOeg7'><form id='rOeg7'><ins id='rOeg7'></ins><ul id='rOeg7'></ul><sub id='rOeg7'></sub></form><legend id='rOeg7'></legend><bdo id='rOeg7'><pre id='rOeg7'><center id='rOeg7'></center></pre></bdo></b><th id='rOeg7'></th></span></q></dt></tr></i><div id='rOeg7'><tfoot id='rOeg7'></tfoot><dl id='rOeg7'><fieldset id='rOeg7'></fieldset></dl></div>
    1. <small id='rOeg7'></small><noframes id='rOeg7'>

      <legend id='rOeg7'><style id='rOeg7'><dir id='rOeg7'><q id='rOeg7'></q></dir></style></legend>
      • <bdo id='rOeg7'></bdo><ul id='rOeg7'></ul>

      Jquery 和 List 中的 switch 语句

      时间:2023-09-07
        <tfoot id='aXCJM'></tfoot>

      • <legend id='aXCJM'><style id='aXCJM'><dir id='aXCJM'><q id='aXCJM'></q></dir></style></legend>

              <tbody id='aXCJM'></tbody>

            <small id='aXCJM'></small><noframes id='aXCJM'>

            • <bdo id='aXCJM'></bdo><ul id='aXCJM'></ul>
              <i id='aXCJM'><tr id='aXCJM'><dt id='aXCJM'><q id='aXCJM'><span id='aXCJM'><b id='aXCJM'><form id='aXCJM'><ins id='aXCJM'></ins><ul id='aXCJM'></ul><sub id='aXCJM'></sub></form><legend id='aXCJM'></legend><bdo id='aXCJM'><pre id='aXCJM'><center id='aXCJM'></center></pre></bdo></b><th id='aXCJM'></th></span></q></dt></tr></i><div id='aXCJM'><tfoot id='aXCJM'></tfoot><dl id='aXCJM'><fieldset id='aXCJM'></fieldset></dl></div>

              1. 本文介绍了Jquery 和 List 中的 switch 语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我想知道我的方法是否有效且正确.但我的代码不起作用,我不知道为什么.

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

                <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                <html xmlns="http://www.w3.org/1999/xhtml">
                <head>
                <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript" charset="utf-8"></script>
                
                 <script type="text/javascript">
                
                 $(document).ready(function() {
                
                
                  function HotelQuery(HotelName) {
                   switch (HotelName) {
                    case 'TimelessHotel': 
                     var strHotelName = 'Timeless Hotel';
                     var strHotelDesc = 'Hotel Description Timeless Hotel';
                     var strHotelPrice = ['980.00', '1,300.00', '1,600.00', '1,500.00', '1,800.00', '300.00', '150.00', '200.00'];
                     var strHotelRoomType = ['Single Room', 'Delux Room','Twin Room', 'Matrimonial Room', 'Presidential Suites', 'Extra Bed', 'Free Breakfast', 'Extra Person'];    
                    ; //end Timeless Hotel
                
                    case 'ParadiseInn': 
                     var strHotelName = 'Paradise Inn';
                     var strHotelDesc = 'Hotel Description Paradise Inn';
                     var strHotelPrice = ['980.00', '1,300.00', '1,600.00', '1,500.00', '1,800.00', '300.00', '150.00', '200.00'];
                     var strHotelRoomType = ['Single Room', 'Delux Room','Twin Room', 'Matrimonial Room', 'Presidential Suites', 'Extra Bed', 'Free Breakfast', 'Extra Person'];    
                    ; //end Paradise Inn
                
                    case 'TetrisHotel': 
                     var strHotelName = 'Tetris Hotel';
                     var strHotelDesc = 'Hotel Description Tetris Hotel';
                     var strHotelPrice = ['980.00', '1,300.00', '1,600.00', '1,500.00', '1,800.00', '300.00', '150.00', '200.00'];
                     var strHotelRoomType = ['Single Room', 'Delux Room','Twin Room', 'Matrimonial Room', 'Presidential Suites', 'Extra Bed', 'Free Breakfast', 'Extra Person'];    
                    ; //end Tetris Hotel 
                
                    case 'JamstoneInn': 
                     var strHotelName = 'Jamstone Inn';
                     var strHotelDesc = 'Hotel Description Jamstone Inn';
                     var strHotelPrice = ['980.00', '1,300.00', '1,600.00', '1,500.00', '1,800.00', '300.00', '150.00', '200.00'];
                     var strHotelRoomType = ['Single Room', 'Delux Room','Twin Room', 'Matrimonial Room', 'Presidential Suites', 'Extra Bed', 'Free Breakfast', 'Extra Person'];    
                    ; //end Jamstone Inn 
                
                   }
                  };
                
                
                 });
                
                   </script>     
                
                <title>hotel query</title>
                </head>
                
                <body>
                
                  <a href="#" onclick="javascript: HotelQuery('TetrisHotel'); alert: (strHotelName, strHotelDesc, strHotelPrice);">Tetris Hotel Query</a>
                
                </body>
                </html>
                

                推荐答案

                你的代码不起作用,因为变量的作用域是函数 HotelQuery.我认为您可能想要做的是从函数返回一个具有属性的对象,并使用不显眼的 JavaScript 方法将点击事件处理程序绑定到 <a> 元素.

                You code doesn't work because the variables are scoped to the function HotelQuery. I think what you might want to do is return an object with properties from the function, and also use the unobtrusive JavaScript approach to bind an click event handler to the <a> element.

                类似

                $(function() {
                    $('a').click(function() {
                        var hotel = HotelQuery('TetrisHotel');
                
                        alert(hotel.name) // alerts 'Tetris Hotel'
                    });
                });
                
                function HotelQuery(HotelName) {
                    var strHotelName;
                    var strHotelDesc;
                    var strHotelPrice;
                    var strHotelRoomType;
                
                    switch (HotelName) { 
                        case 'TimelessHotel': 
                            strHotelName = 'Timeless Hotel';
                            strHotelDesc = 'Hotel Description Timeless Hotel';
                            strHotelPrice = ['980.00', '1,300.00', '1,600.00', '1,500.00', '1,800.00', '300.00', '150.00', '200.00'];
                            strHotelRoomType = ['Single Room', 'Delux Room','Twin Room', 'Matrimonial Room', 'Presidential Suites', 'Extra Bed', 'Free Breakfast', 'Extra Person']; 
                            break; //end Timeless Hotel  
                
                        case 'ParadiseInn': 
                            strHotelName = 'Paradise Inn';
                            strHotelDesc = 'Hotel Description Paradise Inn';
                            strHotelPrice = ['980.00', '1,300.00', '1,600.00', '1,500.00', '1,800.00', '300.00', '150.00', '200.00'];
                            strHotelRoomType = ['Single Room', 'Delux Room','Twin Room', 'Matrimonial Room', 'Presidential Suites', 'Extra Bed', 'Free Breakfast', 'Extra Person'];    
                            break; //end Paradise Inn
                
                        case 'TetrisHotel': 
                            strHotelName = 'Tetris Hotel';
                            strHotelDesc = 'Hotel Description Tetris Hotel';
                            strHotelPrice = ['980.00', '1,300.00', '1,600.00', '1,500.00', '1,800.00', '300.00', '150.00', '200.00'];
                            strHotelRoomType = ['Single Room', 'Delux Room','Twin Room', 'Matrimonial Room', 'Presidential Suites', 'Extra Bed', 'Free Breakfast', 'Extra Person'];  
                            break; //end Tetris Hotel 
                
                        case 'JamstoneInn': 
                            strHotelName = 'Jamstone Inn';
                            strHotelDesc = 'Hotel Description Jamstone Inn';
                            strHotelPrice = ['980.00', '1,300.00', '1,600.00', '1,500.00', '1,800.00', '300.00', '150.00', '200.00'];
                            strHotelRoomType = ['Single Room', 'Delux Room','Twin Room', 'Matrimonial Room', 'Presidential Suites', 'Extra Bed', 'Free Breakfast', 'Extra Person'];    
                            break; //end Jamstone Inn 
                    }
                    return {
                        name: strHotelName,
                        desc: strHotelDesc,
                        price: strHotelPrice,
                        roomType: strHotelRoomType 
                    }
                };
                

                刚刚注意到,除了酒店名称和描述之外,您每次都返回相同的值(您可能只是作为示例这样做,我不确定).您可以在声明时为所有变量分配其值(或将值分配为返回对象的属性),而不是酒店名称和描述,您可以从参数 HotelName.类似的东西

                Just noticed that you're also returning the same values other than the hotel name and description each time (you might have done this just as an example, I'm not sure). You could just assign all variables their value on declaration (or assign the values as properties of the returned object), other than the hotel name and description, which you could assign from the value of the argument for parameter HotelName. Something like

                function hotelQuery(hotelName) {
                    return {
                        name: hotelName,
                        desc: 'Hotel Desciption' + hotelName,
                        // Keep prices as numbers and have a function to display them 
                        // in the culture specific way. Numbers for prices will be easier to deal with
                        price: [980, 1300, 1600, 1500, 1800, 300, 150, 200],
                        roomType: ['Single Room', 'Delux Room','Twin Room', 'Matrimonial Room', 'Presidential Suites', 'Extra Bed', 'Free Breakfast', 'Extra Person']
                    } 
                }
                

                这篇关于Jquery 和 List 中的 switch 语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:从Javascript中的switch case内部中断for循环 下一篇:JavaScript函数没有将我的参数传递给其他函数

                相关文章

                <tfoot id='Lq8v1'></tfoot>
                <i id='Lq8v1'><tr id='Lq8v1'><dt id='Lq8v1'><q id='Lq8v1'><span id='Lq8v1'><b id='Lq8v1'><form id='Lq8v1'><ins id='Lq8v1'></ins><ul id='Lq8v1'></ul><sub id='Lq8v1'></sub></form><legend id='Lq8v1'></legend><bdo id='Lq8v1'><pre id='Lq8v1'><center id='Lq8v1'></center></pre></bdo></b><th id='Lq8v1'></th></span></q></dt></tr></i><div id='Lq8v1'><tfoot id='Lq8v1'></tfoot><dl id='Lq8v1'><fieldset id='Lq8v1'></fieldset></dl></div>

                <small id='Lq8v1'></small><noframes id='Lq8v1'>

                  <bdo id='Lq8v1'></bdo><ul id='Lq8v1'></ul>

                  <legend id='Lq8v1'><style id='Lq8v1'><dir id='Lq8v1'><q id='Lq8v1'></q></dir></style></legend>