简体   繁体   English

当我刷新页面时,Jquery 代码无法完成

[英]When I refresh the page the Jquery code doesn't work done

I have implemented AJAX code which calls an external page in PHP where a DB is queried and creates a table.我已经实现了 AJAX 代码,该代码调用 PHP 中的外部页面,其中查询数据库并创建表。 When AJAX calls the page the jQuery code inserts the PHP table in a <p> tag which creates a sort of "box" through an animation and resizes the box to HEIGHT according to the PHP table. When AJAX calls the page the jQuery code inserts the PHP table in a <p> tag which creates a sort of "box" through an animation and resizes the box to HEIGHT according to the PHP table. When it is called the first time it works correctly, when I then close the "box" using the appropriate button and click on it again to review the box, the latter remains blocked with the standard height of the <p> tag with which it was defined.当它第一次正常工作时,当我使用适当的按钮关闭“框”并再次单击它以查看该框时,后者仍然被它所使用的<p>标签的标准高度阻塞被定义。 How can I fix this and make it work every time I run the jQuery animation without having to refresh the page?每次运行 jQuery animation 时,我如何解决这个问题并使其工作,而无需刷新页面?

<input type="button" value="Close Ripostiglio" class="hidden1" onclick="close1()">
    <p class="par1" id="pa1"> Ripostiglio </p>
    <script>
    function loadDocument(e) {
      var httpRequest = new XMLHttpRequest();
      httpRequest.onreadystatechange = gestisciResponse;
      httpRequest.open("GET","function.php", true);
      httpRequest.send();
      httpRequest.reload();
    }
    function gestisciResponse(e) {
      if (e.target.readyState == 4 && e.target.status == 200) {
        document.getElementById("dinamicZone").innerHTML = e.target.responseText;
      }
    }
                    //OPEN BOX
      $(document).ready(function(){
        //RIPOSTIGLIO
        $(".par1").click(function right(){
          var p = $(".par1");
          var n = $(".hidden1");
          p.animate({left: '300px'}, "slow");
          p.animate({height: '$(#dinamicZone).height()'}, "slow");
          p.animate({width: '350px'}, "slow");
          p.html("<div id='dinamicZone'></div>");
          setTimeout(loadDocument, 2000); //delay the open of table
          n.show();
        });
        function close1(){
        $(".nascosto1").click(function destra(){
          var p = $("#pa1");
          var p = $(".par1");
          var c = $(".hidden1");
          var s = $(".add1");
          p.animate({height: '65px'}, "slow");
          p.animate({width: '150px'}, "slow");
          p.animate({left: '0px'}, "slow");
          s.hide();//TOLGO LA SCRITTA AGGIUNGI
          p.html("Ripostiglio"); //"RIMETTO" FORZATAMENTE LA SCRITTA CANTINETTA VINI
          c.hide();
        });
      }
</script>

The dinamicZone object was destroyed in close1(). dinamicZone object 在 close1() 中被销毁。 So when you click on it again, it has no reference to change size to.因此,当您再次单击它时,它没有更改大小的参考。 Reloading the page will reinitialize the page, thus recreating dinamicZone.重新加载页面将重新初始化页面,从而重新创建 dinamicZone。

Perhaps change the line in close() where you reassign the value of p.HTML.也许更改 close() 中重新分配 p.HTML 值的行。 If you comment out that line, the resizing should work.如果您注释掉该行,则调整大小应该有效。

---- ignore below this ---- ----忽略下面这个----


Without it, you're trying to set the height to 65 when it contains an object that is higher, which is probably why it did not work. 

```
 $(".nascosto1").click(function destra(){
          // var p = $("#pa1");  // duplicate
          var p = $(".par1");
          var c = $(".hidden1");
          var s = $(".add1");
          p.html("Ripostiglio"); //"RIMETTO" FORZATAMENTE LA SCRITTA CANTINETTA VINI
          p.animate({height: '65px'}, "slow");
          p.animate({width: '150px'}, "slow");
          p.animate({left: '0px'}, "slow");
          s.hide();//TOLGO LA SCRITTA AGGIUNGI
          c.hide();
        });
```

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM