<tfoot id='9ZrgK'></tfoot>

      <legend id='9ZrgK'><style id='9ZrgK'><dir id='9ZrgK'><q id='9ZrgK'></q></dir></style></legend>

      <small id='9ZrgK'></small><noframes id='9ZrgK'>

    1. <i id='9ZrgK'><tr id='9ZrgK'><dt id='9ZrgK'><q id='9ZrgK'><span id='9ZrgK'><b id='9ZrgK'><form id='9ZrgK'><ins id='9ZrgK'></ins><ul id='9ZrgK'></ul><sub id='9ZrgK'></sub></form><legend id='9ZrgK'></legend><bdo id='9ZrgK'><pre id='9ZrgK'><center id='9ZrgK'></center></pre></bdo></b><th id='9ZrgK'></th></span></q></dt></tr></i><div id='9ZrgK'><tfoot id='9ZrgK'></tfoot><dl id='9ZrgK'><fieldset id='9ZrgK'></fieldset></dl></div>
          <bdo id='9ZrgK'></bdo><ul id='9ZrgK'></ul>

        document.write() 覆盖文档?

        时间:2023-10-15

      1. <legend id='PxGyT'><style id='PxGyT'><dir id='PxGyT'><q id='PxGyT'></q></dir></style></legend>
            <bdo id='PxGyT'></bdo><ul id='PxGyT'></ul>

                <tbody id='PxGyT'></tbody>

              • <tfoot id='PxGyT'></tfoot>

                  <i id='PxGyT'><tr id='PxGyT'><dt id='PxGyT'><q id='PxGyT'><span id='PxGyT'><b id='PxGyT'><form id='PxGyT'><ins id='PxGyT'></ins><ul id='PxGyT'></ul><sub id='PxGyT'></sub></form><legend id='PxGyT'></legend><bdo id='PxGyT'><pre id='PxGyT'><center id='PxGyT'></center></pre></bdo></b><th id='PxGyT'></th></span></q></dt></tr></i><div id='PxGyT'><tfoot id='PxGyT'></tfoot><dl id='PxGyT'><fieldset id='PxGyT'></fieldset></dl></div>

                  <small id='PxGyT'></small><noframes id='PxGyT'>

                  本文介绍了document.write() 覆盖文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  这个:

                  function myFunction()
                  {
                      document.write("sup");
                  }
                  

                  在 html 中调用如下:

                  called in html like:

                  <div id="myDiv">
                      <script>myFunction();</script>
                  </div>t
                  

                  将字符串 sup 添加到 myDiv div 元素.这正是我想要的.但是,这个:

                  adds a string sup to the myDiv div element. Which is what I want, exactly. However, this:

                  function loadFile(uri)
                  {
                      var r = new XMLHttpRequest();
                      document.write("trying to open: " + uri);
                      r.open('GET', uri, true);
                      r.send(null);
                      r.onreadystatechange = function()
                      {
                          if (r.readyState == 4)
                          {
                              myFunction();
                          }
                      }
                  }
                  
                  function myFunction()
                  {
                      document.write("sup");
                  }
                  

                  这样称呼:

                  <div id="myDiv">
                      <script>loadFile("filename.txt");</script>
                  </div>
                  

                  似乎覆盖了我的整个 html 文件.IE.当我在 Firefox 中运行它时,它只显示字符串 sup (这是页面的全部内容),但页面似乎仍在加载(FF 的加载图标仍然存在动画,显然是无限的).

                  seems to be overwriting my whole html file. I.e. when I run it in Firefox it shows me only the string sup (that's the whole content of the page) but the page seems to be still loading (the loading icon of FF is still there animating, apparently infinitely).

                  首先,这将仅在本地离线使用,作为一种快速便捷的数据呈现方式(使用 html+js 和 Web 浏览器而不是纯文本文件).我想要的是加载一个本地文本文件,然后将它的一些内容作为 html 页面的一部分.与我的第一个示例相同,但首先加载文本文件.

                  First of all, this is going to be used only locally, offline, as a fast and handy way of presenting data (using html+js and web browser instead of plain text file). What I want is to load a local text file and then put some of its content as a part of the html page. The same as in my first example but with loading the text file first.

                  推荐答案

                  问题是当你在文档加载后运行 document.write 时,它​​会覆盖整个文档.如果在此之前运行,它不会覆盖它.

                  The issue is that when you run document.write after the document has loaded, it overwrites the entire document. If it is run before that, it does not overwrite it.

                  您要做的是设置特定元素的innerHtml,例如:

                  What you want to do is set the innerHtml of a specific element, something like:

                  document.getElementById("myDiv").innerHTML="Sup";
                  

                  这篇关于document.write() 覆盖文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:找出完成一个 Ajax 请求需要多长时间 下一篇:如何发送“&amp;"?通过 AJAX 的(和号)字符?

                  相关文章

                  最新文章

                  1. <tfoot id='L123Y'></tfoot>
                      <bdo id='L123Y'></bdo><ul id='L123Y'></ul>
                    <legend id='L123Y'><style id='L123Y'><dir id='L123Y'><q id='L123Y'></q></dir></style></legend>
                    1. <i id='L123Y'><tr id='L123Y'><dt id='L123Y'><q id='L123Y'><span id='L123Y'><b id='L123Y'><form id='L123Y'><ins id='L123Y'></ins><ul id='L123Y'></ul><sub id='L123Y'></sub></form><legend id='L123Y'></legend><bdo id='L123Y'><pre id='L123Y'><center id='L123Y'></center></pre></bdo></b><th id='L123Y'></th></span></q></dt></tr></i><div id='L123Y'><tfoot id='L123Y'></tfoot><dl id='L123Y'><fieldset id='L123Y'></fieldset></dl></div>

                      <small id='L123Y'></small><noframes id='L123Y'>