light7ui 刷新子页面 js不能加载的问题

来源:互联网 发布:阿里云建ss 编辑:程序博客网 时间:2024/05/20 06:23

当使用light7库写移动端,页面刷新后,当前页面js事件失效
http://light7.cn/components/#init
http://light7.cn/components/#router
原文
Call $.init() to init all components in page。

We will not init page on document loaded, because $.config.autoInit = false;. You should call $.init() on document loaded. $.init method will init all components in page, and trigger a pageInit event after init complete. You should call $.init after all pageInit events has binded.

But the page Loaded By router will always be inited.

Do not modify $.init please.

If you set $.config.autoInit = true;, the$.initmethod will auto be called after document onload. But your pageInit binds may have not executed at this time. So, please do not set autoInit=true, unless you don’t listen to pageInit event or you can make sure that your code will be right.

see demofor more usage.

JS和CSS等脚本问题
当通过ajax加载新页面的时候,路由器会自动忽略新页面的JS和CSS脚本。所以请把全部页面的脚本都打包到入口页面。在demo中我们每个页面都引用了相同的脚本,是为了在子页面刷新的时候也可以用。

在入口index页面引入所有js,调用$.init()初始化每个页面对应的pageinit做法如下:

 $(document).ready(function(){//关键 //页面1  $(pageinit,#id,function(){   $(".button").click(function(){   //只有加上document.ready和$.init(),次方法才会在页面刷新后,重新初始化起效  })  //页面2 $(pageinit,#id2,function(){   $(".button2").click(function(){   //只有加上document.ready和$.init(),次方法才会在页面刷新后,重新初始化起效  })  }) $.init()//关键 })
0 1
原创粉丝点击