【问题标题】:JQuery innerHTML after changePage not workingchangePage 后的 JQuery innerHTML 不起作用
【发布时间】:2020-12-23 02:17:21
【问题描述】:

我正在使用 jQuery mobile(对于 Cordova 应用程序),我想在解决方案中更改为不同的页面,然后在该新页面中更改 div 的内容:

        $.mobile.changePage("otherPage.html");
        $("#div_in_otherPage").html("Hello");

但它不起作用。它移动到新页面,但 DIV 没有改变。我尝试不更改到新页面并将具有相同 ID 的 DIV 放在上一页中,它确实更改了该 DIV 的内容。是什么让我认为 $.html 附加到上一页的 DOM 上。 还尝试使用带有 innerHTML 的普通 javascript 而不是 $.html,但结果相同。

在 changePage 之后我还需要做其他事情吗?还是我应该使用其他方法?

提前致谢。

【问题讨论】:

    标签: jquery jquery-mobile innerhtml


    【解决方案1】:

    当然它不会自动加载页面,所以当页面准备好时,我不得不将 innerHTML 放入一个事件中:

    $(document).on("pagebeforeshow", "#otherPage", function(event,data){
        $("#div_in_otherPage").html("Hello");
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-22
      • 2011-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多