【问题标题】:How to update partial page(DIV) if the DIV loads a subpage with a redirection button?如果 DIV 加载带有重定向按钮的子页面,如何更新部分页面(DIV)?
【发布时间】:2012-07-04 09:42:42
【问题描述】:

我很困惑我可以将子页面嵌入到父页面的 DIV 中, 但我不能限制此类 DIV 中子页面的任何操作。 如果我按下属于子页面的按钮, 它会将整个页面刷新到新页面。未部分更新。

我的 HTML 如下:

父页面:

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

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

子页面:

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

如何只更新父页面的DIV而不刷新整个页面?

最好的问候, 乔什

【问题讨论】:

  • 尝试添加return false;在 onClick 命令中,所以它不会触发它的原生“按钮推送”。

标签: jquery html ajax load


【解决方案1】:

您的 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>

你的 child-page.html 应该是:

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

您也可以使用\" 代替'。所以onclick="$("#container").load("/child-page/")" 不正确!

我用marquee标签告诉你整个父页面没有刷新。

【讨论】:

    【解决方案2】:
    <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>
    

    【讨论】:

    • 我刚刚将上面的html添加到我的子页面,它似乎不起作用:(按下按钮后没有响应
    猜你喜欢
    • 1970-01-01
    • 2013-01-24
    • 1970-01-01
    • 1970-01-01
    • 2013-07-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多