0

我正在尝试使用子页面更改作为父页面一部分的 div 的内容。为了更新内容,我使用了 innerHTML。内容看起来很好,但图像上的 onclick 事件不起作用。这是我的代码,该代码在 Mozilla firefox 中有效,但在 Chrome 和 Safari 中无效。此外,它不适用于 iPad Safari 浏览器。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
    <head>
        <title>TEMP</title>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" />
        <script src="http://code.jquery.com/jquery-1.8.3.js"></script>
        <script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
        <script src="scripts/jquery-1.8.2.min.js"></script>         
        <script>
            $(document).ready(function() {
                    //this is the parent element
                    parent.document.getElementById('hd').innerHTML = document.getElementById('temp').innerHTML;
            });
        </script>
    </head>
    <body>
        <div id="fakeshare" style="float: left;margin-top: -30px;z-index:1000000;position: absolute;vertical-align: middle">    
        </div>
        <!-- this is the content I try to populate in the parent element -->
        <div id = "temp" style="visibility: hidden">
        <div style="float:left">
            <img id="backbtn2" class="imgtopbutton" src="images/facebook-cancel.png" onclick="javascript:history.go(-1)" align="left" style="margin-left:12px;margin-top:10px"/>
            <img class="imgtopbutton" src="images/facebook-post.png" align="right" style="margin-top:-31px;margin-left:545px" onclick="javascript:history.go(-1)">
        </div>
        </div>
    </body>
</html>
4

2 回答 2

1

尝试使用 $('#hd').parent().html($('#temp').html());

于 2013-01-19T09:02:54.343 回答
1

你试一试:

$("#hd").html($("#temp").html());
于 2013-01-19T09:15:01.093 回答