{"id":667,"date":"2011-01-28T09:41:29","date_gmt":"2011-01-28T01:41:29","guid":{"rendered":""},"modified":"2014-03-11T22:36:24","modified_gmt":"2014-03-11T14:36:24","slug":"%e7%bb%99%e9%a1%b5%e9%9d%a2%e4%b8%8a%e7%9a%84%e5%ae%b9%e5%99%a8%e8%bf%bd%e5%8a%a0%e6%96%87%e6%9c%ac%e7%9a%84%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"http:\/\/www.xiaoyebailong.com\/index.php\/2011\/01\/28\/667.htm","title":{"rendered":"\u7ed9\u9875\u9762\u4e0a\u7684\u5bb9\u5668\u8ffd\u52a0\u6587\u672c\u7684\u65b9\u6cd5"},"content":{"rendered":"<p>\u559c\u6b22\u7528\u76f4\u63a5\u6539\u5199innerHTML\u7684\u65b9\u6cd5\u6765\u7ed9\u5bb9\u5668\u8ffd\u52a0\u6587\u672c\u5185\u5bb9\uff0c\u4f8b\u5982\uff1a<\/p>\n<p>\n&nbsp;<\/p>\n<p>var el = document.getElementById(&#8216;myid&#8217;); <br \/>\nel.innerHTML += &#8216;\u8981\u8ffd\u52a0\u7684\u6587\u672c\u5185\u5bb9&#8217;;<\/p>\n<p>\n&nbsp;<\/p>\n<p>\u8fd9\u6837\u5199\u5f53\u7136\u662f\u65b9\u4fbf\u7684\uff0c\u4f46\u662f\u8fd9\u662f\u6700\u597d\u7684\u65b9\u6cd5\u5417\uff1f<br \/>\n\u4e4b\u524d\u5728IE\u4e0b\u8e29\u8fc7\u4e00\u4e2a&ldquo;\u5751&rdquo;\uff0c\u90a3\u5c31\u662f\u5f53IE\u4e0b\u7684\u9875\u9762\u91ccpre\u6807\u8bb0\u6216\u8005textarea\u6807\u8bb0\u7684innerHTML\u88ab\u6539\u5199\u7684\u65f6\u5019\uff0c\u5b83\u4eec\u7684\u683c\u5f0f\u4f1a\u4e22\u5931\u3002\u8fd9\u662f\u6d4f\u89c8\u5668\u7684bug\u5417\uff1f\u5982\u679c\u4f60\u975e\u8981\u53bb\u5f04\u6e05\u539f\u56e0\u7684\u8bdd\uff0c\u6211\u8ba4\u4e3a\u8fd9\u5176\u5b9e\u662f\u56e0\u4e3aIE\u89e3\u6790html\u7684document_fragment\u89c4\u5219\u9020\u6210\u7684\uff0c\u4e0d\u80fd\u8bf4\u8fd9\u662fbug\uff08FF\u548c\u5176\u4ed6\u6d4f\u89c8\u5668\u663e\u7136\u6709\u5b83\u4eec\u81ea\u5df1\u7684\u60f3\u6cd5\uff09\u3002\u9664\u4e86pre\u548ctextarea\u4e24\u4e2a\u6807\u8bb0\u7684\u95ee\u9898\u4e4b\u5916\uff0cinnerHTML\u8fd8\u6709\u53e6\u4e00\u4e2a\u95ee\u9898\uff0c\u5c31\u662f\u5b83\u7684\u6267\u884c\u6548\u7387\u5176\u5b9e\u5e76\u4e0d\u9ad8\u3002<br \/>\n\u90a3\u4e48\uff0c\u4e00\u4e2a\u53ef\u80fd\u9047\u5230\u95ee\u9898\u4e14\u6548\u7387\u4e0d\u9ad8\u7684\u7528\u6cd5\uff0c\u6709\u6ca1\u6709\u6539\u8fdb\u7a7a\u95f4\u5462\uff1f\u7b54\u6848\u662f\u6709\u7684\u3002\u4e8b\u5b9e\u4e0a\u5728\u5bb9\u5668\u5185\u8ffd\u52a0\u7eaf\u6587\u672c\u65f6\uff0c\u6700\u4f73\u7684\u65b9\u6cd5\u5e76\u4e0d\u662f\u4f7f\u7528innerHTML\uff0c\u800c\u662f\u4f7f\u7528DOM\u7684TextNode\uff08\u7406\u8bba\u4e0aIE\u8fd8\u6709\u4e00\u4e2a\u975e\u6807\u51c6\u7684innerText\u5c5e\u6027\uff0c\u4f46\u5b83\u663e\u7136\u4e0d\u5728\u6211\u4eec\u7684\u8003\u8651\u8303\u56f4\u5185\uff09\u3002\u4f8b\u5982\uff1a<\/p>\n<p>\n&nbsp;<\/p>\n<p>var el = document.getElementById(&#8216;myid&#8217;); <br \/>\nel.appendChild(document.createTextNode( &#8216;\u8981\u8ffd\u52a0\u7684\u6587\u672c\u5185\u5bb9&#8217;));<\/p>\n<p>\n&nbsp;<\/p>\n<p>\u548c\u76f4\u63a5\u4fee\u6539innerHTML\u76f8\u6bd4\uff0c\u8ffd\u52a0TextNode\u8282\u70b9\u7684\u65b9\u5f0f\u9664\u4e86\u901f\u5ea6\u5feb\u5e76\u4e14\u683c\u5f0f\u6b63\u786e\u4e4b\u5916\uff0c\u8fd8\u6709\u81ea\u52a8\u66ff\u6362html\u6807\u8bb0\u7684\u597d\u5904\uff08\u8fd9\u4e5f\u5c31\u662f\u8bf4\uff0c\u5bf9\u4e8e\u7eaf\u6587\u672c\u7684\u524d\u7aef\u5c55\u793a\uff0c\u5e76\u4e0d\u9700\u8981\u989d\u5916\u7684\u5904\u7406\u51fd\u6570\uff0c\u53ea\u8981\u5c06\u5b83\u653e\u5165TextNode\u4e2d\uff0c\u5c31\u4e00\u5b9a\u662f\u5b89\u5168\u7684\uff09\u3002\u6700\u540e\u6211\u4eec\u53ef\u4ee5\u7528\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\u7ed3\u675f\u6211\u4eec\u7684\u8bdd\u9898\uff1a<\/p>\n<p>\n&nbsp;<\/p>\n<p>&lt;style type=&quot;text\/css&quot;&gt; <br \/>\ntextarea{ <br \/>\nwidth:100%; <br \/>\nheight:100px; <br \/>\n} <br \/>\n&lt;\/style&gt; <br \/>\n&lt;textarea id=&quot;t&quot;&gt; <br \/>\nabc <br \/>\ndef <br \/>\n&lt;\/textarea&gt; <br \/>\n&lt;textarea id=&quot;t2&quot;&gt; <br \/>\nabc <br \/>\ndef <br \/>\n&lt;\/textarea&gt; <\/p>\n<p>&lt;pre id=&quot;p&quot;&gt; <br \/>\nabc <br \/>\ndef <br \/>\n&lt;\/pre&gt; <br \/>\n&lt;pre id=&quot;p2&quot;&gt; <br \/>\nabc <br \/>\ndef <br \/>\n&lt;\/pre&gt; <\/p>\n<p>&lt;textarea id=&quot;i&quot;&gt;\u8981\u63d2\u5165\u7684\u5185\u5bb9&lt;\/textarea&gt; <br \/>\n&lt;button onclick=&quot;insert()&quot;&gt;\u63d2\u5165&lt;\/button&gt; <\/p>\n<p>&lt;script&gt; <br \/>\nfunction insert(){ <br \/>\nt.innerHTML += i.value; <br \/>\np.innerHTML += i.value; <br \/>\nt2.appendChild(document.createTextNode(i.value)); <br \/>\np2.appendChild(document.createTextNode(i.value)); <br \/>\n} <br \/>\n&lt;\/script&gt;<br \/>\n&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u559c\u6b22\u7528\u76f4\u63a5\u6539\u5199innerHTML\u7684\u65b9\u6cd5\u6765\u7ed9\u5bb9\u5668\u8ffd\u52a0\u6587\u672c\u5185\u5bb9\uff0c\u4f8b\u5982\uff1a &nbsp; var el = document.getElementById(&#8216;myid&#8217;); el.innerHTML += &#8216;\u8981\u8ffd&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"topic":[],"class_list":["post-667","post","type-post","status-publish","format-standard","hentry","category-technology"],"_links":{"self":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts\/667","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=667"}],"version-history":[{"count":1,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts\/667\/revisions"}],"predecessor-version":[{"id":66537,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts\/667\/revisions\/66537"}],"wp:attachment":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/media?parent=667"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/categories?post=667"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/tags?post=667"},{"taxonomy":"topic","embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/topic?post=667"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}