在index.html页面中调用外部HTML页面时页眉和页脚位置不固定?

我在jquery mobile的index.html页面中调用一个外部html页面时遇到页眉和页脚问题。 以下是我遵循的示例代码:

的index.html

..
..

main.js

  $("header").attr("data-position","fixed").attr("data-tap-toggle","false"); $("footer").attr("data-position","fixed").attr("data-tap-toggle","false"); 

https://stackoverflow.com/questions/10578545/header-footer-positions-not-fixed-when-calling-external-html-page-in-index-htm/sample.html

  ......  
..

在上面的index.html页面中调用“#single”和“#faq”时,页眉和页脚正确显示其位置是否已修复,但是当调用https://stackoverflow.com/questions/10578545/header-footer-positions-not-fixed-when-calling-external-html-page-in-index-htm/sample.html(外部HTML页面)时,页眉和页脚位置未显示在固定职位。 他们在动。

问题在于您调用attr()方法的时间。 您需要绑定到pagebeforecreate。 这样,在JQM增强标记之前,会设置页眉和页脚属性。 即

 $(document).on('pagebeforecreate', function(){ $("header").attr("data-position","fixed").attr("data-tap-toggle","false"); $("footer").attr("data-position","fixed").attr("data-tap-toggle","false"); }); 

注意:如果您的jQuery版本是1.7之前的版本,请使用bind或delegate而不是on()