我懂文件。写作被认为是坏习惯;我希望整理一份理由清单,提交给第三方供应商,告诉他们为什么不应该使用文档。编写分析代码的实现。
请附上申领文件的理由。下面是一个坏习惯。
我懂文件。写作被认为是坏习惯;我希望整理一份理由清单,提交给第三方供应商,告诉他们为什么不应该使用文档。编写分析代码的实现。
请附上申领文件的理由。下面是一个坏习惯。
当前回答
它使用XML呈现来分割页面(如XHTML页面)。
最好:一些浏览器切换回HTML渲染,一切工作正常。
可能:某些浏览器在XML呈现模式下禁用了document.write()函数。
最糟糕的情况:某些浏览器在使用document.write()函数时会触发一个XML错误。
其他回答
一些比较严重的问题:
document.write (henceforth DW) does not work in XHTML DW does not directly modify the DOM, preventing further manipulation (trying to find evidence of this, but it's at best situational) DW executed after the page has finished loading will overwrite the page, or write a new page, or not work DW executes where encountered: it cannot inject at a given node point DW is effectively writing serialised text which is not the way the DOM works conceptually, and is an easy way to create bugs (.innerHTML has the same problem)
最好使用安全且DOM友好的DOM操作方法
文件的缺点。写作主要取决于这3个因素:
)实现
write()主要用于在需要内容时立即将内容写入屏幕。这意味着它发生在任何地方,要么在JavaScript文件中,要么在HTML文件中的脚本标记中。由于script标记被放置在这样的HTML文件中的任何地方,在与网页中的HTML交织在一起的脚本块中使用document.write()语句是一个坏主意。
b)呈现
Well designed code in general will take any dynamically generated content, store it in memory, keep manipulating it as it passes through the code before it finally gets spit out to the screen. So to reiterate the last point in the preceding section, rendering content in-place may render faster than other content that may be relied upon, but it may not be available to the other code that in turn requires the content to be rendered for processing. To solve this dilemma we need to get rid of the document.write() and implement it the right way.
c)不可能的操作
一旦写好了,就结束了。如果不进入DOM,我们就不能返回去操作它。
它使用XML呈现来分割页面(如XHTML页面)。
最好:一些浏览器切换回HTML渲染,一切工作正常。
可能:某些浏览器在XML呈现模式下禁用了document.write()函数。
最糟糕的情况:某些浏览器在使用document.write()函数时会触发一个XML错误。
它可以阻止你的页面
文档。写只在页面加载时工作;如果在页面加载完成后调用它,它将覆盖整个页面。
这实际上意味着你必须从一个内联脚本块中调用它——这将阻止浏览器处理接下来页面的部分内容。直到写入块完成,脚本和图像才会被下载。
Pro:
这是从外部(到您的主机/域)脚本嵌入内联内容的最简单方法。 你可以覆盖一个frame/iframe中的全部内容。在更现代的Ajax技术广泛可用之前(1998-2002),我经常在菜单/导航部分使用这种技术。
Con:
它序列化渲染引擎,直到加载外部脚本,这可能比内部脚本花费更长的时间。 它通常以这样一种方式使用,即将脚本放在内容中,这被认为是糟糕的形式。