jquerymobile:当 mobile.changepage 使用 reloadpage:true 调用时,目标页面

jquerymobile: target page not refreshing when called by mobile.changepage useing reloadpage:true

本文关键字:目标 调用 reloadpage mobile changepage 使用 jquerymobile true      更新时间:2023-09-26

我正在尝试使用如下所示mobile.changepage通过ajax调用加载页面:

mobile.changePage( "index.html", {transition: "slide", reloadPage: true, data: id})

我尝试在index.html上使用所有功能,例如:

$( '#mainMenu' ).live( 'pageinit',function(event){var movie_id = location.search;});

页面已加载,但我无法在index.html页面上获取"id"的值,只要我硬刷新它就可以工作。

我做错了什么?

谢谢罗德里

假设您将单个参数传递给 page2 ,您可以在 page2 中使用 location.search 来获取 movie 变量,但我发现它不适用于常规浏览器。因此,在结果页面中,您需要解析$(this).data('url') .

此外,page2中的脚本代码必须位于DIV#page2块内,因为当下一页更改时,标题 HTML 中的内容不会更改(正如另一个成员所注意到的那样)。

该脚本阻止:

页1

<script language="javascript">
    $( '#mainMenu' ).live( 'pageinit',function(event){
        $('.btnTxtSearch').bind('click',function () {
            var movieName = $('#txtMovieTitle').val();
            if (!movieName || movieName.length == 0 || movieName == null) {
                alert('Please insert a title before clicking the button');
                return false;
            } //end of if
            $.mobile.changePage( "page2.html", {transition: "slide", reloadPage: true, data: movieName}); 
        });
    });
</script>

页2

<script language="javascript">
//Without this pageinit may be called multiple times in back and forth use case.   
$('#page2').die( 'pageinit');
$('#page2').live( 'pageinit',function(){
    var movieName = $(this).data('url').split('?')[1];
    //Debug:
    alert(movieName);
});     

</script>