【问题标题】:Refreshing a div creates a duplicate in struts2刷新 div 会在 struts2 中创建一个副本
【发布时间】:2012-08-20 06:33:43
【问题描述】:

我是 Javascript 新手,所以请多多包涵。

我有代码在子窗口关闭时刷新父窗口的 div。问题是当 div 的内容刷新时它会创建一个副本,我不知道为什么。我的代码如下。

在父级的head 标记内,我正在这样做:

<html>
<head>
<script language="javascript" type="text/javascript">
function ParentWindowFunction()
{
    $(".mydiv").load("Welcome.jsp");
    return false;
}
</script>
</head>
<body>

<div class="mydiv">
    <img src="<s:property  value="#session.img"/>"  id="img"  width="200"  height="150" />
</div>
</body>

</html>

在子窗口的head 标签内我有:

<html>
<head>
<script type="text/javascript">
function refreshAndClose() 
{

    window.opener.ParentWindowFunction();

    window.close();
}
</script>
</head>
<body  onbeforeunload="refreshAndClose();">
...
</body>
</html>

【问题讨论】:

  • 您的回复是否还包含一个元素,该元素具有 mydiv 作为类名的一部分?
  • Welcome.jsp返回了什么?它的主体中是否还包含&lt;div class="mydiv"&gt;
  • @RobinMaben 是的罗宾,只有一次

标签: javascript jquery html refresh


【解决方案1】:

我找到了我的问题的解决方案,而不是刷新 div,我正在像这样重新加载整个页面

<script>     
    function winopen()
    {
        chatterinfo = window.open('fileupload.jsp',"chatterwin","scrollbars=no,resizable=yes, width=400, height=300, location=no, toolbar=no, status=no");

        chatterinfo.focus();        
    }
</script>
<script language="javascript" type="text/javascript">
    function ParentWindowFunction()
    {
        window.location="Login.action?uname=${uname}&&pass=${pass}";
    }
</script>
</head>
<body>

<div class="mydiv">
<img src="<s:property  value="#session.img"/>"  id="img"  width="200"  height="150" />
</div>
</body>
</html>

在子窗口的头部标签内我有:

<html>
<head>
<script type="text/javascript">
    function refreshAndClose() 
    {
        window.opener.ParentWindowFunction();
        window.close();
    }
</script>
</head>
<body >
<input type=button onclick="refreshAndClose();" />
</body>
</html>

【讨论】:

    猜你喜欢
    • 2018-09-20
    • 1970-01-01
    • 2020-08-24
    • 2020-06-01
    • 1970-01-01
    • 2021-12-16
    • 1970-01-01
    • 2015-07-21
    • 2017-08-19
    相关资源
    最近更新 更多