【问题标题】:How to refresh/reload a slide out panel (jquery)如何刷新/重新加载滑出面板(jquery)
【发布时间】:2014-06-05 16:14:53
【问题描述】:

我有一个带有评论表单的滑出面板,用户提交评论表单后,会出现“谢谢”,问题是,在我关闭面板后,再次将其滑出以进行第二次评论,“谢谢”还在!我希望看到一个新的未填写的评论表单。

如何显示一个全新的原始评论表单,而不是之前会话的剩余内容?

代码:

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.css">
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $.post("comment.pl", {
        comment:$("#comment").val(),
    },
    function(data,status){
      document.getElementById('div2').innerHTML = "THANK YOU";
    });
  });
});
</script>
</head>
<body>
<div data-role="page" id="pageone">
  <div data-role="main" class="ui-content">
    <p>Click on the link to see the slide effect.</p>
    <a href="#pagetwo" data-transition="slide">Slide to Dialog Page</a>
  </div>
</div>  <!-- pageone -->
<div data-role="popup" data-dialog="true" id="pagetwo" >
<div data-role="main" class="ui-content">
    <div id="div2">
    <b>Enter Comment</b>
    <br>
    <textarea name="comment" id="comment" data-role="none" rows=5 cols=30 onkeypress="if(event.keyCode==13){return false;}" onKeyDown="limitText2(this,100);" onKeyUp="limitText2(this,100);" style="resize:none;"></textarea>
    <br>
    <button data-inline="true"><font size=+2 color=#333333>Enter</font></button>
    <a href="#pageone" data-ajax="false">Go to Page One</a>
    </div> <!-- div2 -->
</div> <!-- ui-content -->
</div>  <!-- pagetwo -->
</body>
</html>                

【问题讨论】:

  • 我没有看到面板,我看到了一个弹出窗口...data-dialog="true"?!请先浏览一下 jQM 的 demo 和 API,抱歉,你的代码是一团糟。

标签: javascript jquery jquery-mobile mobile


【解决方案1】:

与其改变div2的内容,不如改成.append.show一个元素。如果我们在运行时重新创建 div2 的内容,我们需要在这个新代码上重新应用所有 JS,以便刷新它并使其能够正确发布数据。

所以,创建一个在单击按钮时出现的#success div:

...
 function(data,status){
      $('#success').show();
    });
...

页面过渡动画完成时会运行一个事件:

$( document ).bind( "mobileinit", function() {
    $('div[data-role="main"]').live('pagehide',function(event, ui){
        //the 'pageHide' happens when the main is hidden
     $('#success').hide();

    });
 });

【讨论】:

  • 我做了一些显示/隐藏测试,但显示仍然没有刷新,我输入了一些垃圾并隐藏,然后显示,垃圾仍然存在,没有完成刷新:(
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-12-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-17
  • 2012-10-07
  • 2011-05-17
相关资源
最近更新 更多