这是我目前的设置.
这是我的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'); }); });