0

outerHTML からの新しいコンテンツである新しいコンテンツでページを更新することは可能ですか? ページを2秒まで更新したい、0〜2秒処理してinnerHTMLなどで新しいHTMLを取得したいという問題がありますが、outerHTMLから新しいコンテンツを取得した後。このコンテンツを outerHTML からの HTML で更新するのは困難です。

私のコード例の下:

<script>
    // code blablabla to get new content. This has been fix code, and below code to start refresh page with outerHTML.
    window.onload = function() {
        tes();
    };

    function tes() {
        var htmlAll = document.documentElement.outerHTML;
        setTimeout(function(){howCodeRefresh()}, 2000);
        function howCodeRefresh() {
            // how code to refresh page and replace all content with variable htmlAll
        };
    };
</script>

私の質問:それは可能ですか?はいの場合、それを行う方法は?

ありがとう。

4

1 に答える 1

0

質問を明確に説明することはできません。質問を解決するために jquery で ajax を試すことができます。基本的なデモは次のとおりです。

    <div id = "target"></div>


    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript">
        window.onload = loadHtml;
        function loadHtml(){
             $.get("your/server/page.html",function(response){
                   $("#target").html(response);     //Here is your html response
             },'html');
         }
    </script>

これは、jquery ajax のドキュメントです。

于 2014-03-04T03:19:01.840 に答える