<bdo id='m98LC'></bdo><ul id='m98LC'></ul>
    1. <tfoot id='m98LC'></tfoot>

        <legend id='m98LC'><style id='m98LC'><dir id='m98LC'><q id='m98LC'></q></dir></style></legend>

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

        <i id='m98LC'><tr id='m98LC'><dt id='m98LC'><q id='m98LC'><span id='m98LC'><b id='m98LC'><form id='m98LC'><ins id='m98LC'></ins><ul id='m98LC'></ul><sub id='m98LC'></sub></form><legend id='m98LC'></legend><bdo id='m98LC'><pre id='m98LC'><center id='m98LC'></center></pre></bdo></b><th id='m98LC'></th></span></q></dt></tr></i><div id='m98LC'><tfoot id='m98LC'></tfoot><dl id='m98LC'><fieldset id='m98LC'></fieldset></dl></div>
      1. document.write() 覆盖文档?

        document.write() overwriting the document?(document.write() 覆盖文档?)

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

          1. <tfoot id='gMmXR'></tfoot>

                <bdo id='gMmXR'></bdo><ul id='gMmXR'></ul>
                <i id='gMmXR'><tr id='gMmXR'><dt id='gMmXR'><q id='gMmXR'><span id='gMmXR'><b id='gMmXR'><form id='gMmXR'><ins id='gMmXR'></ins><ul id='gMmXR'></ul><sub id='gMmXR'></sub></form><legend id='gMmXR'></legend><bdo id='gMmXR'><pre id='gMmXR'><center id='gMmXR'></center></pre></bdo></b><th id='gMmXR'></th></span></q></dt></tr></i><div id='gMmXR'><tfoot id='gMmXR'></tfoot><dl id='gMmXR'><fieldset id='gMmXR'></fieldset></dl></div>
                • <legend id='gMmXR'><style id='gMmXR'><dir id='gMmXR'><q id='gMmXR'></q></dir></style></legend>
                    <tbody id='gMmXR'></tbody>
                  本文介绍了document.write() 覆盖文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  这个:

                  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() 覆盖文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  SCRIPT5: Access is denied in IE9 on xmlhttprequest(SCRIPT5:在 IE9 中对 xmlhttprequest 的访问被拒绝)
                  XMLHttpRequest module not defined/found(XMLHttpRequest 模块未定义/未找到)
                  Show a progress bar for downloading files using XHR2/AJAX(显示使用 XHR2/AJAX 下载文件的进度条)
                  How can I open a JSON file in JavaScript without jQuery?(如何在没有 jQuery 的情况下在 JavaScript 中打开 JSON 文件?)
                  How do I get the HTTP status code with jQuery?(如何使用 jQuery 获取 HTTP 状态码?)
                  quot;Origin null is not allowed by Access-Control-Allow-Originquot; in Chrome. Why?(“Access-Control-Allow-Origin 不允许 Origin null在铬.为什么?)

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

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

                      <tfoot id='ZLNiM'></tfoot>
                        <tbody id='ZLNiM'></tbody>

                          • <bdo id='ZLNiM'></bdo><ul id='ZLNiM'></ul>
                            <legend id='ZLNiM'><style id='ZLNiM'><dir id='ZLNiM'><q id='ZLNiM'></q></dir></style></legend>