简体   繁体   English

如果DIV使用重定向按钮加载子页面,如何更新部分页面(DIV)?

[英]How to update partial page(DIV) if the DIV loads a subpage with a redirection button?

I'm confused with that I can embed a child-page into the parent-page's DIV, but I can't restrict any actions of the child-page within such DIV. 我对可以将子页面嵌入到父页面的DIV中感到困惑,但是我不能将子页面的任何动作限制在此类DIV中。 If I push the button which is belong to the child-page, it will refresh whole page to the new one. 如果我按下属于子页面的按钮,它将刷新整个页面到新页面。 Not partially updating. 没有部分更新。

My HTML is as follows: 我的HTML如下:

The parent-page: 父页面:

        < div id="container" >
        < /div>

        <script>
         $("#container").load("/child-page/");
        </script>

The child-page: 子页面:

        < input type="button" name="Create" 
          value="Create" 
          onclick="$("#container").load("/child-page/")" />

How can I only update the parent-page's DIV without refreshing whole page ? 如何仅更新父页面的DIV而无需刷新整个页面?

Best regards, Josh 最好的问候,乔希

<div id="container"></div>
<input type="button" name="flavor_create_btn" value="Create Flavor" />
<script>
$(document).ready(function(){
   $('input[name="flavor_create_btn"]').on('click', function(){
      $("#container").load("/child-page/");
   });
});
</script>

Your parent-page.html page should be: 您的parent-page.html页面应为:

<script type="text/javascript" language="javascript">
$(document).ready(function(){
    $("#container").load("./child-page.html");
});
</script>

<marquee>Parent Page!</marquee>
<div id="container"></div>

and your child-page.html should be: 并且您的child-page.html应该为:

<input type="button" name="Create" value="Create" onclick="$('#container').load('./child-page.html')" />

Also you can use \\" instead of ' . So onclick="$("#container").load("/child-page/")" is incorrect!. 您也可以使用\\"而不是' 。因此onclick="$("#container").load("/child-page/")"是不正确的!

I used marquee tag to tell you that the whole parent page is not refreshed. 我使用marquee标记来告诉您整个父页面没有刷新。

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

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