加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – Jquery Mobile:新的Ajax加载页面没有加载新的JS

发布时间:2020-12-13 17:41:48 所属栏目:PHP教程 来源:网络整理
导读:这是我目前的设置. 我在jquery移动框架上运行了两个页面. index.php article.php 在麻烦的标题我有一个名为评级的js文件. 这是我的js ratings.js: $(document).ready(function(){ $("#rating_1").click(function () { $("#rating_2").css('backgroundPositi
这是我目前的设置.

我在jquery移动框架上运行了两个页面.

> index.php
> article.php

在麻烦的标题我有一个名为评级的js文件.

这是我的js ratings.js:

$(document).ready(function(){
    $("#rating_1").click(function () {
        $("#rating_2").css('backgroundPosition','0px 0px');
        $(this).css('backgroundPosition','-45px 0px');
    }); 
});

当我加载index.php然后转到article.php时,我的触发器都没有给ratings.js工作.

如果我添加rel =“external”或data-ajax =“false”我的触发器工作.
然而,我失去了装载轮出现的能力.

有什么建议?

谢谢!

解决方法

Important: Use $(document).bind('pageinit'),not
$(document).ready()

The first thing you learn in jQuery is to call code inside the
$(document).ready() function so everything will execute as soon as
the DOM is loaded. However,in jQuery Mobile,Ajax is used to load the
contents of each page into the DOM as you navigate,and the DOM ready
handler only executes for the first page. To execute code whenever a
new page is loaded and created,you can bind to the pageinit event.
This event is explained in detail at the bottom of this page.

> http://jquerymobile.com/demos/1.1.0/docs/api/events.html

尝试:

$(document).bind('pageinit',function() {
    $("#rating_1").click(function() {
        $("#rating_2").css('backgroundPosition','-45px 0px');
    }); 
});

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读