【问题标题】:jquery mobile scripts does not work after page refresh页面刷新后jquery移动脚本不起作用
【发布时间】:2013-03-19 15:16:47
【问题描述】:

我正在使用 JQM 和 JSF。 在页面中,在我触发 h:commondbutton 并且它的操作重新运行字符串 null '' 之后, 页面刷新和任何脚本都不起作用。 我在就绪函数和移动 pageinit 函数中设置了断点,但它们都不起作用。 当我删除 jquerymobile 库时,它可以工作。 对此有任何想法..

<script src="js/jquery-1.8.3.js"></script>
<script type="text/javascript">
  //<![CDATA[
  $(document).on('mobileinit', function() {
    $.mobile.defaultPageTransition = 'slide';
    $.mobile.hashListeningEnabled = false;
  });
  //]]>
</script>        
<script src="js/jquery.mobile-1.2.0.js"></script>



   $(document).ready(function(){
    //some codes here
});


<div data-role="page" id="page1" >
     <script type="text/javascript">

        $('#page1').live('pageinit', function() {  

     $("#getNewValuesLinkId").bind('click', function() {   
       $("#getnewValues").trigger("click");//this jsf button
       });    

  });


</div>

jsf h:commonbutton 处理并返回空字符串“”。页面刷新,任何脚本都不起作用。

【问题讨论】:

  • 请提供一些Html和jQuery代码。
  • 你在使用 jsf 代码在移动 web 视图中进行渲染吗?

标签: jquery jsf jquery-mobile


【解决方案1】:

我遇到过类似的问题。您可以尝试将 Javascript 代码直接放在脚本标签中,即不在 $(document).ready 或 $(document).on 中。

例如不是这个:

<script>
    $(document).on('mobileinit', function() {
    $.mobile.defaultPageTransition = 'slide';
    $.mobile.hashListeningEnabled = false;
  });
</script>

但是这个代替(在适当的地方):

<script>
    $.mobile.defaultPageTransition = 'slide';
    $.mobile.hashListeningEnabled = false;
</script>

【讨论】:

  • 我试过了,但没有用.. :( 问题是所有脚本都不起作用,在 ready 和 pageinit 中。
  • 我终于发现了问题,不知道是什么原因,但有一个解决方法。
【解决方案2】:

我有解决方法,但不知道问题的原因。

  $(document).on('mobileinit', function() {
    $.mobile.defaultPageTransition = 'slide';
    $.mobile.hashListeningEnabled = false;
  });

这是上面的 funksion 在页面加载时工作。但是我的项目在刷新后它们不起作用。 Thefefore there is 意味着此页面不会再次重新加载。 它让我想到了 ajax 方法。 ajax处理后,页面的任何脚本都会被调用,所以ready、pageinit、mobile init函数不会被调用。

所以我把代码放在下面的 mobileinit 中。

$.mobile.ajaxEnabled = false;

解决办法是这样的

  $(document).on('mobileinit', function() {
    $.mobile.defaultPageTransition = 'slide';
    $.mobile.hashListeningEnabled = false;
    $.mobile.ajaxEnabled = false;
  });

我又来了,不过这个页面怎么能使用 ajax?

【讨论】:

    猜你喜欢
    • 2013-11-07
    • 2016-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多