Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
未使用jquery mobile加载动态内容_Jquery_Jquery Mobile - Fatal编程技术网

未使用jquery mobile加载动态内容

未使用jquery mobile加载动态内容,jquery,jquery-mobile,Jquery,Jquery Mobile,我有以下jquery移动页面的代码。当我直接运行它时,它可以工作,但当我从另一个页面链接到它时,它不会加载。我曾尝试在引用链接中关闭数据ajax,但没有任何区别。有什么想法吗 以下是代码: var urlQuery = location.search; urlQuery = urlQuery.replace('?', ''); var split = urlQuery.split('='); var id = split[1]; $(document).delegate('[data-role

我有以下jquery移动页面的代码。当我直接运行它时,它可以工作,但当我从另一个页面链接到它时,它不会加载。我曾尝试在引用链接中关闭数据ajax,但没有任何区别。有什么想法吗

以下是代码:

var urlQuery = location.search;
urlQuery = urlQuery.replace('?', '');
var split = urlQuery.split('=');
var id = split[1];

$(document).delegate('[data-role="page"]', 'pageinit', function(){
    $.get('../ws/bars.php?id=' + id, function(data) { 
        $('[data-role="content"]').html(data);
        $('[data-href="specials"]').trigger('click');
    });
});


$(document).delegate('[data-role="navbar"] a', 'click', function(event){
    $('.content_div').hide(); // hide all the .content_div's
    $('#' + $(this).attr('data-href')).show(); // display the div that's been clicked   $('a.pageTab').removeAttr('style'); // remove styling from the buttons
    $(this).attr('style','color: #eee;'); // add styling to the active button
});
无论我从中得到什么答案,请告诉我为什么以及为什么,这样我才能理解这里发生了什么

谢谢

您的初始$.get函数调用似乎正在全局范围内运行。这意味着它在页面加载时运行,而不是在后续页面加载时运行,因为jQuery Mobile通过AJAX将外部页面拉入同一DOM。因此,要对每个伪页面运行AJAX请求,我将绑定到pageinit事件:

此外,如果每个页面上的元素具有以下ID,sun/mon/等,则应将它们更改为类或以某种方式使其唯一,以便DOM中不会同时有多个具有相同ID的元素。您可以使用$.mobile.activePage引用轻松选择当前页面上的元素:

$.mobile.activePage.find('.sun')...

这对我上面的代码是有效的,但我希望我的问题的答案能在我的其他页面上有效。但是,当我点击一个链接并转到第二个页面时,这不起作用-第二个页面上的动态内容不会加载。而且,我在这个页面上只有那些ID的元素。我的应用程序中的每个页面都不同,它们都位于单独的HTML文件中。在我尝试document.delegate之前,我已经将第二页中的代码添加到我的问题中,这样您就可以以原始格式看到那里发生了什么
$.mobile.activePage.find('.sun')...