来自jqm 1.0.1和jquery 1.6.4的jqm 1.3.2和jquery 1.9.1升级打破了我的弹出窗口

时间:2013-10-06 00:14:32

标签: javascript jquery html jquery-mobile

我正在尝试将运行在1.0.1和jquery 1.6.4版本上的旧jquery移动网站升级到最新版本,并且在替换某些用于选择弹出按钮的jquery部分时遇到问题。 以下是旧版本中生成的HTML

                <div class="ui-selectmenu ui-overlay-shadow ui-corner-all ui-body-a pop in" style="top: 30px; right: 30px;">
                    <div class="ui-header ui-bar-a">

                <h1 class="ui-title">Search Results</h1>

                <a class="ui-btn-left ui-btn ui-btn-up-a ui-btn-icon-notext ui-btn-corner-all ui-shadow" href="#" data-iconpos="notext" data-icon="delete" title="Close" data-theme="a" style="display: none;">
                <span class="ui-btn-inner ui-btn-corner-all">
                <span class="ui-btn-text">Close</span>
                <span class="ui-icon ui-icon-delete ui-icon-shadow"></span>
                </span>
                </a>

                    </div>
                    <ul id="action_menu-menu" class="ui-selectmenu-list ui-listview" role="listbox" aria-labelledby="action_menu-button" data-theme="a">
                        <li class="ui-selectmenu-placeholder ui-btn ui-btn-up-a ui-btn-icon-right ui-li ui-btn-active" data-icon="false" data-option-index="0" role="option" tabindex="0" data-theme="a" aria-selected="true">
                            <div class="ui-btn-inner ui-li">
                                <div class="ui-btn-text">
                <a class="ui-link-inherit" href="#">Search Results</a>

                                </div>
                            </div>
                        </li>
                        <li class="ui-btn ui-btn-icon-right ui-li ui-btn-up-a" data-icon="false" data-option-index="1" role="option" tabindex="-1" data-theme="a" aria-selected="false">
                            <div class="ui-btn-inner ui-li">
                                <div class="ui-btn-text">
                <a class="ui-link-inherit" href="#">Home</a>

                                </div>
                            </div>
                        </li>
                        <li class="ui-btn ui-btn-icon-right ui-li ui-btn-up-a" data-icon="false" data-option-index="2" role="option" tabindex="-1" data-theme="a" aria-selected="false">
                            <div class="ui-btn-inner ui-li">
                                <div class="ui-btn-text">
                <a class="ui-link-inherit" href="#">Email</a>

                                </div>
                            </div>
                        </li>
                    </ul>
                </div>   

接下来是我当前代码生成的HTML

                <div id="action_menu-listbox-screen" class="ui-popup-screen in"></div>
                <div id="action_menu-listbox-popup" class="ui-popup-container ui-popup-active" style="max-width: 1564px; top: 30.0001px; left: 14px;" tabindex="0">
                    <div id="action_menu-listbox" class="ui-selectmenu ui-popup ui-body-a ui-overlay-shadow ui-corner-all">
                        <div class="ui-header ui-bar-a">

                <h1 class="ui-title">Search Results</h1>

                        </div>
                        <ul id="action_menu-menu" class="ui-selectmenu-list ui-listview" role="listbox" aria-labelledby="action_menu-button" data-theme="a" data-divider-theme="b">
                            <li class="ui-selectmenu-placeholder ui-btn ui-btn-up-a ui-btn-icon-right ui-li ui-first-child" data-option-index="0" data-icon="false" data-placeholder="true" role="option" data-corners="false" data-shadow="false" data-iconshadow="true" data-wrapperels="div" data-iconpos="right" data-theme="a" aria-selected="false">
                                <div class="ui-btn-inner ui-li">
                                    <div class="ui-btn-text">
                <a class="ui-link-inherit" href="#" tabindex="-1">Search Results</a>

                                    </div>
                                </div>
                            </li>
                            <li class="ui-btn ui-btn-icon-right ui-li ui-btn-up-a" data-option-index="1" data-icon="false" role="option" data-corners="false" data-shadow="false" data-iconshadow="true" data-wrapperels="div" data-iconpos="right" data-theme="a" aria-selected="false">
                                <div class="ui-btn-inner ui-li">
                                    <div class="ui-btn-text">
                <a class="ui-link-inherit" href="#" tabindex="-1">Home</a>

                                    </div>
                                </div>
                            </li>
                            <li class="ui-btn ui-btn-icon-right ui-li ui-last-child ui-btn-up-a" data-option-index="2" data-icon="false" role="option" data-corners="false" data-shadow="false" data-iconshadow="true" data-wrapperels="div" data-iconpos="right" data-theme="a" aria-selected="false">
                                <div class="ui-btn-inner ui-li">
                                    <div class="ui-btn-text">
                <a class="ui-link-inherit" href="#" tabindex="-1">Email</a>

                                    </div>
                                </div>
                            </li>
                        </ul>
                    </div>
                </div>
                </div>

我没有更改旧代码,除了具有实时方法的javascript,我正在努力完全理解和替换。如下

<script type="text/javascript">
                  $(document).bind("mobileinit", function(){
                   $.mobile.listview.prototype.options.theme= "c";
                       $.mobile.defaultTransition = 'none';
                        $.mobile.pushStateEnabled = false;
                        $.extend(  $.mobile , { 
                              ajaxFormsEnabled : false,
                              ajaxLinksEnabled : false,
                                  ajaxEnabled:false,
                                  // loadingMessage: false
                         });
                  });
                </script>

        <script src="</jquery.mobile-1.0.1.min.js" type="text/javascript"></script>
        <%--Script added by B37914 for CR43399 on 7th March,2012--%>
        <script src="/m_alert.js" type="text/javascript"></script>
        <script src="/m_common.js" type="text/javascript"></script>

        <script>
            var mobileMainViewUrl = 'http;//www.yahoo.com';
            var urlForEmailAction = document.location.href;

             $('#header-logo').click(function(){alert("this is the header alert");});

            $(document).bind("mobileinit", function(){
                  $.mobile.defaultTransition = 'none';        
            });

            **
  。

$( “选择[ID = 'action_menu']”)生活( “改变”,的ActionHandler);

**

            $(document).ready(function(){       
                if($("li[class*='ui-btn-icon-right']")!=null){
                    $("li[class*='ui-btn-icon-right']").each(function(ind,elm){
                        var anch=$(this).find("a[class*='ui-link-inherit']");
                        var arrowIcn=$(elm).find("span[class='ui-icon ui-icon-arrow-r ui-icon-shadow']");
                        if(anch !=null && arrowIcn!=null){
                            $(arrowIcn).appendTo(anch);
                        }
                    });
                    }
            });

            function showActionMenu(assetId,assetType){

                var language=document.getElementById("m_lang").value;
                var pageTitle = $('title').html();
                pageTitle = pageTitle.replace("&amp;","and");
                pageTitle = pageTitle.replace("amp;","");
                pageTitle = pageTitle.replace("&","and");
                //changed by b36050 for cr-48634 on 17 jan 2013
                callActionButton('action_menu',pageTitle,urlForEmailAction,true,assetId,assetType,deleteFavorite,language);

                }

        </script>

请检查在http://jsfiddle.net/hgafoor/85qy3/

生成这两个HTML和.js文件的代码

我尝试了各种选项,但是当我使用点击时,我无法以某种方式获得选项的价值。我已经尝试使用#action_menu-menu作为选择器并尝试了bind和委托我不明白为什么在较新版本中,作为action_menu的id被添加为主要div以生成弹出窗口而不是ui-selectmenu。我已经坚持了一段时间了,如果有人可以帮我解决这个问题,那将是一个很好的解决方案

1 个答案:

答案 0 :(得分:0)

对我有用的是相当简单的解决方案:@Omar

我学到的一些观点: 1.需要在实际调用它之前加载actionHandler函数(这是一个没脑子,但我是一个初学者很难缠绕我的脑袋)。 2.在加载JQM和其他.js文件之前,需要调用mobileinit函数。 3.对actionHandler的调用需要放在ready()中,以便触发操作。

$(document).ready(function(){

        var mobileMainViewUrl = "http://www.yahoo.com";
        var urlForEmailAction = document.location.href;
        var deleteFavorite = "";

         $('select').on('change', actionHandler);
});