jQuery技术:在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()

      以上就是jQuery教程分享在index.html页面中调用外部HTML页面时页眉和页脚位置不固定?相关内容,想了解更多jQuery开发(异常处理)及jQuery教程关注计算机技术网(www.ctvol.com)!)。

      本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

      ctvol管理联系方式QQ:251552304

      本文章地址:https://www.ctvol.com/jquerytutorial/558370.html

      (0)
      上一篇 2021年1月26日
      下一篇 2021年1月26日

      精彩推荐