{"id":67263,"date":"2015-08-21T13:47:34","date_gmt":"2015-08-21T05:47:34","guid":{"rendered":"http:\/\/www.xiaoyebailong.com\/?p=67263"},"modified":"2015-08-21T13:47:34","modified_gmt":"2015-08-21T05:47:34","slug":"js-document-write%e4%bd%bf%e7%94%a8%e4%bb%8b%e7%bb%8d","status":"publish","type":"post","link":"http:\/\/www.xiaoyebailong.com\/index.php\/2015\/08\/21\/67263.htm","title":{"rendered":"js document.write()\u4f7f\u7528\u4ecb\u7ecd"},"content":{"rendered":"<div id=\"art_demo\">\u4e00\u4e2a\u6700\u57fa\u672c\u7684JavaScript\u547d\u4ee4\u662fdocument.write\u3002\u8fd9\u4e2a\u547d\u4ee4\u7b80\u5355\u5730\u6253\u5370\u6307\u5b9a\u7684\u6587\u672c\u5185\u5bb9\u5230\u9875\u9762\u4e0a\u3002\u4e3a\u4e86\u9010\u5b57\u6253\u5370\u6587\u672c\uff0c\u5728\u6253\u5370\u7684\u6587\u672c\u5b57\u7b26\u4e32\u52a0\u4e0a\u5355\u5f15\u53f7<\/div>\n<div class=\"blank3\"><\/div>\n<div id=\"con_all\"><\/div>\n<div id=\"art_content\">\n<p>\u5728\u8f7d\u4eba\u9875\u9762\u540e\uff0c\u6d4f\u89c8\u5668\u8f93\u51fa\u6d41\u81ea\u52a8\u5173\u95ed\uff1b\u5728\u6b64\u4e4b\u540e\uff0c\u4efb\u4f55\u4e00\u4e2a\u5bf9\u5f53\u524d\u9875\u9762\u8fdb\u884c\u64cd\u4f5c\u7684document.write()\u65b9\u6cd5\u5c06\u6253\u5f00\u2014\u4e2a\u65b0\u7684\u8f93\u51fa\u6d41\u3002\u5b83\u5c06\u6e05\u9664\u5f53\u524d\u9875\u9762\u5185\u5bb9(\u5305\u62ec\u6e90\u6587\u6863\u7684\u4efb\u4f55\u53d8\u91cf\u6216\u503c)\u3001\u56e0\u6b64\uff0e\u5047\u5982\u5e0c\u671b\u7528\u811a\u672c\u751f\u6210\u7684HTML\u66ff\u6362\u5f53\u524d\u9875\u9762\uff0c\u5c31\u5fc5\u987b\u628aHTML\u5185\u5bb9\u8fde\u63a5\u8d77\u6765\u8d4b\u7ed9\u4e00\u4e2a\u53d8\u91cf\u3001\u4f7f\u7528\u4e00\u4e2adocument.write()\u65b9\u6cd5\u5b8c\u6210\u5199\u64cd\u4f5c\uff0c\u4e0d\u5fc5\u6e05\u9664\u6587\u6863\u5e76\u6253\u5f00\u4e00\u4e2a\u65b0\u6570\u636e\u6d41\uff0c\u4e00\u4e2adocument.write()\u8c03\u7528\u5c31\u53ef\u5b8c\u6210\u6240\u6709\u7684\u64cd\u4f5c\u3002<\/p>\n<p>\u5173\u4e8edocument.write()\u65b9\u6cd5\u8fd8\u6709\u4e00\u70b9\u8981\u8bf4\u660e\u7684\u662f\u5b83\u7684\u76f8\u5173\u65b9\u6cd5document.close()\u3002\u811a\u672c\u5411\u7a97\u53e3(\u4e0d\u7ba1\u662f\u672c\u7a97\u53e3\u6216\u5176\u4ed6\u7a97\u53e3)\u5199\u5b8c\u5185\u5bb9\u540e\uff0e\u5fc5\u987b\u5173\u95ed\u8f93\u51fa\u6d41\u3002\u5728\u5ef6\u65f6\u811a\u672c\u7684\u6700\u540e\u4e00\u4e2adocument.write()\u65b9\u6cd5\u540e\u9762\uff0e\u5fc5\u987b\u786e\u4fdd\u542b\u6709document.close()\u65b9\u6cd5\uff0c\u4e0d\u8fd9\u6837\u505a\u5c31\u4e0d\u80fd\u663e\u793a\u56fe\u7247\u548c\u8868\u5355\u3002\u5e76\u4e14\uff0c\u4efb\u4f55\u540e\u9762\u8c03\u7528\u7684document.write()\u65b9\u6cd5\u53ea\u4f1a\u628a\u5185\u5bb9\u8ffd\u52a0\u5230\u9875\u9762\u540e\uff0c\u800c\u4e0d\u4f1a\u6e05\u9664\u73b0\u6709\u5185\u5bb9\u6765\u5199\u5165\u65b0\u503c\u3002<\/p>\n<p><strong>document.write\u65b9\u6cd5<\/strong><\/p>\n<p>\u4e00\u4e2a\u6700\u57fa\u672c\u7684JavaScript\u547d\u4ee4\u662fdocument.write\u3002\u8fd9\u4e2a\u547d\u4ee4\u7b80\u5355\u5730\u6253\u5370\u6307\u5b9a\u7684\u6587\u672c\u5185\u5bb9\u5230\u9875\u9762\u4e0a\u3002\u4e3a\u4e86\u9010\u5b57\u6253\u5370\u6587\u672c\uff0c\u5728\u6253\u5370\u7684\u6587\u672c\u5b57\u7b26\u4e32\u52a0\u4e0a\u5355\u5f15\u53f7\u3002<\/p>\n<div class=\"codetitle\"><a id=\"copybut36568\" class=\"copybut\"><\/a><u>\u590d\u5236\u4ee3\u7801<\/u>\u4ee3\u7801\u5982\u4e0b:<\/div>\n<div id=\"code36568\" class=\"codebody\">\ndocument.write(&#8216;Hello World!&#8217;);<\/div>\n<p>\u4e0a\u9762\u7684js\u4ee3\u7801\u5c06\u4f1a\u5728\u9875\u9762\u4e0a\u663e\u793a\u51fa&#8221;Hello World!&#8221;<br \/>\n\u4f60\u53ef\u4ee5\u4f7f\u7528document.write \u6253\u5370\u53d8\u91cf\u3002\u8f93\u5165\u53d8\u91cf\u540d\u79f0\u4e0d\u52a0\u4e0a\u5f15\u53f7\uff0c\u5982\u4e0b\uff1a<\/p>\n<div class=\"codetitle\"><a id=\"copybut28282\" class=\"copybut\"><\/a><u>\u590d\u5236\u4ee3\u7801<\/u>\u4ee3\u7801\u5982\u4e0b:<\/div>\n<div id=\"code28282\" class=\"codebody\">\nvar mytext = &#8220;Hello again&#8221;;<br \/>\ndocument.write(mytext);<\/div>\n<p>\u6ce8\u610f\uff1a\u5982\u679c\u53d8\u91cf\u540d\u79f0\u52a0\u4e0a\u5f15\u53f7\uff0c\u5c06\u4f1a\u6253\u5370\u51fa\u53d8\u91cf\u540d\u79f0\uff08\u4e0d\u4f1a\u6253\u5370\u53d8\u91cf\u503c\uff09\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u201c+\u201d\u7b26\u53f7\u6765\u8fde\u63a5\u53d8\u91cf\u503c\u548c\u6587\u672c\u5b57\u7b26\u4e32\u3002<\/p>\n<div class=\"codetitle\"><a id=\"copybut6256\" class=\"copybut\"><\/a><u>\u590d\u5236\u4ee3\u7801<\/u>\u4ee3\u7801\u5982\u4e0b:<\/div>\n<div id=\"code6256\" class=\"codebody\">\nvar colour1 = &#8220;purple&#8221;;<br \/>\nvar colour2 = &#8220;pink&#8221;;<br \/>\ndocument.write(&#8216;&lt;p&gt;colour1: &#8216; + colour1 + &#8216;&lt;br&gt;colour2: &#8216; + colour2 + &#8216;&lt;\/p&gt;&#8217;);<\/div>\n<p>\u6253\u5370\u7ed3\u679c\u5982\u4e0b\uff1a<\/p>\n<p>colour1: purple<br \/>\ncolour2: pink<\/p>\n<p><strong>document.write\u4e5f\u591a\u7528\u4e8e\u52a0\u8f7djs\u5e7f\u544a<\/strong><\/p>\n<div class=\"codetitle\"><a id=\"copybut45777\" class=\"copybut\"><\/a><u>\u590d\u5236\u4ee3\u7801<\/u>\u4ee3\u7801\u5982\u4e0b:<\/div>\n<div id=\"code45777\" class=\"codebody\">\ndocument.write(&#8216;&lt;scri&#8217;+&#8217;pt src=&#8221;http:\/\/www.jb51.net\/ad.js&#8221; type=&#8221;text\/javascript&#8221;&gt;&lt;\/s&#8217;+&#8217;cript&gt;&#8217;);<br \/>\ndocument.write(&#8220;&lt;scri&#8221;+&#8221;pt src=&#8217;http:\/\/www.jb51.net\/ad.js&#8217; type=&#8217;text\/javascript&#8217;&gt;&lt;\/s&#8221;+&#8221;cript&gt;&#8221;);<br \/>\ndocument.write(&#8220;&lt;scri&#8221;+&#8221;pt src=\\&#8221;http:\/\/www.jb51.net\/ad.js\\&#8221; type=\\&#8221;text\/javascript\\&#8221;&gt;&lt;\/s&#8221;+&#8221;cript&gt;&#8221;);<\/div>\n<p>\u4e00\u822c\u5916\u9762\u7528\u5355\u5f15\u53f7(\u53cc\u5f15\u53f7)\u8fde\u63a5\u5b57\u7b26\uff0c\u91cc\u9762\u7684\u5c31\u8981\u7528\u53cc\u4fe1\u53f7(\u5355\u5f15\u53f7)\uff0c\u8fd9\u6837\u5c31\u4e0d\u4f1a\u9519\u4e86\u3002\u5f53\u7136\u4e5f\u53ef\u4ee5\u7528\u8f6c\u4e49\u5b57\u7b26\uff0c\u4f46\u8fd9\u6837\u4ee5\u540e\u4fee\u6539\u6bd4\u8f83\u9ebb\u70e6\u3002<\/p>\n<p><strong>document.write\u8fd9\u79cd\u65b9\u5f0f\u52a0\u8f7d\u7684js\u662f\u5f02\u6b65\u7684<\/strong><\/p>\n<div class=\"codetitle\"><a id=\"copybut27214\" class=\"copybut\"><\/a><u>\u590d\u5236\u4ee3\u7801<\/u>\u4ee3\u7801\u5982\u4e0b:<\/div>\n<div id=\"code27214\" class=\"codebody\">\n&lt;!DOCTYPE HTML PUBLIC &#8220;-\/\/W3C\/\/DTD HTML 4.01\/\/EN&#8221; &#8220;http:\/\/www.w3.org\/TR\/html4\/strict.dtd&#8221;&gt;<br \/>\n&lt;html lang=&#8221;ru&#8221;&gt;<br \/>\n&lt;head&gt;<br \/>\n&lt;title&gt;&lt;\/title&gt;<br \/>\n&lt;meta http-equiv=&#8221;Content-Type&#8221; content=&#8221;text\/html;charset=gb2312&#8243;&gt;<br \/>\n&lt;\/head&gt;<br \/>\n&lt;script type=&#8221;text\/javascript&#8221;&gt;<br \/>\nfunction load(js){<br \/>\nvar s = document.createElement(&#8216;script&#8217;);<br \/>\ns.setAttribute(&#8216;type&#8217;,&#8217;text\/javascript&#8217;);<br \/>\ns.setAttribute(&#8216;src&#8217;,js);<br \/>\nvar head = document.getElementsByTagName(&#8216;head&#8217;);<br \/>\nhead[0].appendChild(s);<\/p>\n<p>}<br \/>\nfunction write(js){<br \/>\ndocument.write(&#8216;&lt;script type=&#8221;text\/javascript&#8221; src=&#8221;&#8216;+js+'&#8221; &gt; &lt;\\\/script&gt;&#8217;);<br \/>\n}<\/p>\n<p>load(&#8220;http:\/\/www.jb51.net\/js\/2011\/jquery-1.5.1.min.js&#8221;);<br \/>\n\/\/ write(&#8220;http:\/\/www.jb51.net\/js\/2011\/jquery-1.5.1.min.js&#8221;);<\/p>\n<p>&lt;\/script&gt;<br \/>\n&lt;script&gt;<br \/>\nalert($);<br \/>\n&lt;\/script&gt;<\/p><\/div>\n<p>\u95ee\uff1a \u7528createElement(&#8220;script&#8221;\uff09\u7684\u65b9\u5f0f\u52a0\u8f7d\uff0c\u8c03\u7528\u51fd\u6570\u5c31\u4f1a\u62a5\u9519\uff0c\u7528document.write\u5c31\u4e0d\u62a5\u9519?\u7b54\u6848\uff1a<\/p>\n<p>\u5bf9\u4e8e\u52a8\u6001\u521b\u5efa\u7684js \u5f15\u7528\u800c\u8a00 \uff0c\u9488\u5bf9\u4e0d\u540c\u7684\u6d4f\u89c8\u5668\u6709\u4e0d\u540c\u7684\u53cd\u5e94<br \/>\n\u697c\u4e3b\u7684\u8fd9\u79cd\u5199\u6cd5 \u5bf9 FF Opera \u800c\u8a00 load \u65b9\u6cd5\u662f\u963b\u585e\u7684 \u6545alert($)\u80fd\u8f93\u51fa\uff0c\u800c\u5bf9IE Chrome Safria \u800c\u8a00 \u662f\u975e\u963b\u585e\u7684 \u6240\u4ee5\u5c31\u4f1a\u62a5\u9519<br \/>\n\u800cdocument.write\u7684\u65b9\u5f0f\uff0c\u5bf9\u6240\u6709\u6d4f\u89c8\u5668\u800c\u8a00\u90fd\u662f\u963b\u585e\u7684 \u5373\u540c\u6b65\u7684 \u6240\u4ee5alert($)\u4f1a\u8f93\u51fa\u6b63\u786e\u7ed3\u679c<\/p>\n<p>\u7528 <code>document.write<\/code> \u8f93\u51fa <code>&lt;script type='text\/javascript'&gt;&lt;\/script&gt;<\/code> \u600e\u4e48\u641e\u90fd\u4e0d\u884c\uff0c\u6d4f\u89c8\u5668\u4e2d\u53ea\u4f1a\u663e\u793a\u5f62\u5982 <code>\");<\/code> \u7684\u4e1c\u897f\uff0c\u6ce8\u91ca\u6389\u8fd9\u884c\u4ee3\u7801\u4ecd\u7136\u51fa\u9519\u2026\u2026<\/p>\n<p>\u6211\u731c\u60f3\u53ef\u80fd\u662f\u67d0\u4e2a\u5b57\u7b26\u9700\u8981\u8f6c\u4e49\uff0c\u4f46\u6ca1\u8bd5\u9a8c\u6210\u529f\u3002\u76f4\u5230\u770b\u5230<a rel=\"nofollow\" href=\"http:\/\/www.faqts.com\/knowledge_base\/view.phtml\/aid\/841\">\u8fd9\u7bc7\u6587\u7ae0<\/a>\u624d\u660e\u767d\u4e86\uff0c\u6211\u6765\u8f6c\u8ff0\u4e00\u4e0b\u8981\u70b9\uff1a<\/p>\n<blockquote><p>\u4f7f\u7528 <code>document.write<\/code> \u8f93\u51fa HTML \u6807\u7b7e\uff08\u5c24\u5176\u662f <code>&lt;script&gt;<\/code> \u6807\u7b7e\uff09\u7684\u65f6\u5019\uff0c\u9700\u8981\u5c06\u95ed\u5408\u6807\u7b7e\u8fdb\u884c\u8f6c\u4e49\uff0c\u5426\u5219\u6d4f\u89c8\u5668\u5728\u5339\u914d\u95ed\u5408\u6807\u7b7e\u65f6\u53d1\u751f\u9519\u8bef\u3002\u8fd9\u6837\u5199\u662f\u6ca1\u95ee\u9898\u7684\uff1a<br \/>\n<code><br \/>\ndocument.write('&lt;\\\/script&gt;');<br \/>\ndocument.write('&lt;\\\/body&gt;');<br \/>\ndocument.write('&lt;\\\/html&gt;');<br \/>\n<\/code><\/p>\n<p>\u5982\u679c\u4f60\u7684 <code>document.write<\/code> \u662f\u5728\u4e00\u4e2a .js \u6587\u4ef6\u4e2d\uff0c\u5219\u4e0d\u9700\u8981\u8fd9\u6837\u505a\u3002<\/p><\/blockquote>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u4e2a\u6700\u57fa\u672c\u7684JavaScript\u547d\u4ee4\u662fdocument.write\u3002\u8fd9\u4e2a\u547d\u4ee4\u7b80\u5355\u5730\u6253\u5370\u6307\u5b9a\u7684\u6587\u672c\u5185\u5bb9\u5230\u9875\u9762\u4e0a\u3002\u4e3a\u4e86\u9010\u5b57\u6253\u5370\u6587\u672c\uff0c\u5728\u6253\u5370\u7684\u6587\u672c\u5b57\u7b26\u4e32\u52a0\u4e0a\u5355\u5f15\u53f7 \u5728\u8f7d\u4eba\u9875\u9762\u540e\uff0c\u6d4f\u89c8\u5668\u8f93\u51fa\u6d41\u81ea\u52a8\u5173\u95ed\uff1b\u5728\u6b64\u4e4b\u540e\uff0c\u4efb\u4f55\u4e00\u4e2a\u5bf9\u5f53\u524d\u9875\u9762\u8fdb\u884c\u64cd\u4f5c\u7684docu&#8230;<\/p>\n","protected":false},"author":1,"featured_media":67264,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,1],"tags":[131,132,23],"topic":[],"class_list":["post-67263","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-htmlcss","category-technology","tag-document-write","tag-javascript","tag-js"],"_links":{"self":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts\/67263","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/comments?post=67263"}],"version-history":[{"count":1,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts\/67263\/revisions"}],"predecessor-version":[{"id":67265,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts\/67263\/revisions\/67265"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/media\/67264"}],"wp:attachment":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/media?parent=67263"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/categories?post=67263"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/tags?post=67263"},{"taxonomy":"topic","embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/topic?post=67263"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}