{"id":1947,"date":"2024-11-10T11:04:31","date_gmt":"2024-11-10T03:04:31","guid":{"rendered":"https:\/\/fwq.ai\/blog\/1947\/"},"modified":"2024-11-10T11:04:31","modified_gmt":"2024-11-10T03:04:31","slug":"javascript-%e4%b8%ad-alert-%e4%b8%ad%e6%96%87%e4%b9%b1%e7%a0%81%e7%9a%84%e5%8e%9f%e5%9b%a0%e6%9c%89%e5%93%aa%e4%ba%9b%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/1947\/","title":{"rendered":"JavaScript \u4e2d alert \u4e2d\u6587\u4e71\u7801\u7684\u539f\u56e0\u6709\u54ea\u4e9b\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173062028421472.jpg\" class=\"aligncenter\" title=\"JavaScript \u4e2d alert \u4e2d\u6587\u4e71\u7801\u7684\u539f\u56e0\u6709\u54ea\u4e9b\uff1f\u63d2\u56fe\" alt=\"JavaScript \u4e2d alert \u4e2d\u6587\u4e71\u7801\u7684\u539f\u56e0\u6709\u54ea\u4e9b\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>javascript \u4e2d alert \u4e2d\u6587\u4e71\u7801\u63a2\u7a76<\/strong><\/p>\n<p>\u5728 javascript \u4e2d\uff0c\u6709\u65f6\u5728\u5c06\u4e2d\u6587\u6587\u672c\u8f93\u51fa\u5230 alert \u7a97\u53e3\u65f6\u4f1a\u9047\u5230\u4e2d\u6587\u4e71\u7801\u7684\u95ee\u9898\u3002\u8fd9\u53ef\u80fd\u662f\u7531\u4e8e\u4ee5\u4e0b\u539f\u56e0\u9020\u6210\u7684\uff1a<\/p>\n<p><strong>1. js \u6587\u4ef6\u7f16\u7801\u9519\u8bef<\/strong><\/p>\n<p>\u786e\u4fdd js \u6587\u4ef6\u7684\u7f16\u7801\u65b9\u5f0f\u4e0e html \u6587\u4ef6\u7684\u7f16\u7801\u65b9\u5f0f\u4e00\u81f4\u3002\u4f8b\u5982\uff0c\u5982\u679c html \u6587\u4ef6\u4f7f\u7528 utf-8 \u7f16\u7801\uff0c\u5219 js \u6587\u4ef6\u4e5f\u5e94\u4f7f\u7528 utf-8 \u7f16\u7801\u3002<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p><strong>2. \u5b57\u7b26\u4e32\u7f16\u7801\u4e0d\u5f53<\/strong><\/p>\n<p>\u76f4\u63a5\u5728 alert \u4e2d\u4f7f\u7528\u4e2d\u6587\u5b57\u7b26\u4e32\u53ef\u80fd\u4f1a\u5bfc\u81f4\u4e71\u7801\u3002\u53ef\u4ee5\u4f7f\u7528\u8f6c\u4e49\u5e8f\u5217\u6765\u6b63\u786e\u7f16\u7801\u5b57\u7b26\u4e32\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre>alert('uesfa');<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u91cc\uff0c&#8217;uesfa&#8217; \u8868\u793a\u4e2d\u6587\u6c49\u5b57 &#8220;\u4e2d&#8221; \u7684 unicode \u7f16\u7801\u3002<\/p>\n<p><strong>3. \u811a\u672c\u6807\u7b7e charset \u8bbe\u7f6e\u65e0\u6548<\/strong><\/p>\n<p>\u5728 &lt;script&gt; \u6807\u7b7e\u4e2d\u8bbe\u7f6e charset \u5c5e\u6027\u53ef\u80fd\u65e0\u6548\uff0c\u56e0\u4e3a\u5b83\u4ec5\u9002\u7528\u4e8e\u5916\u90e8\u811a\u672c\u6587\u4ef6\u3002\u5bf9\u4e8e\u5d4c\u5165\u5f0f\u811a\u672c\uff0c\u5efa\u8bae\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\u6765\u8bbe\u7f6e\u7f16\u7801\uff1a&lt;\/script&gt;<\/p>\n<pre>&lt;meta http-equiv=\"Content-Type\" content=\"text\/html; charset=utf-8\" \/&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4. bom\uff08\u5b57\u8282\u987a\u5e8f\u6807\u8bb0\uff09\u5e72\u6270<\/strong><\/p>\n<p>\u6709\u4e9b\u7f16\u8f91\u5668\u53ef\u80fd\u4f1a\u5728\u4fdd\u5b58 js \u6587\u4ef6\u65f6\u5728\u6587\u4ef6\u5f00\u5934\u6dfb\u52a0 bom\uff08\u5b57\u8282\u987a\u5e8f\u6807\u8bb0\uff09\u3002bom \u53ef\u80fd\u4f1a\u5e72\u6270 alert \u7a97\u53e3\u7684\u7f16\u7801\uff0c\u5bfc\u81f4\u4e2d\u6587\u4e71\u7801\u3002\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u6587\u672c\u7f16\u8f91\u5668\u5220\u9664 bom \u6765\u89e3\u51b3\u6b64\u95ee\u9898\u3002<\/p>\n<p><strong>5. \u7279\u6b8a\u5b57\u7b26\u8f6c\u4e49<\/strong><\/p>\n<p>\u5982\u679c\u4e2d\u6587\u6587\u672c\u5305\u542b\u7279\u6b8a\u5b57\u7b26\uff08\u4f8b\u5982\u5f15\u53f7\u3001\u53cd\u659c\u6760\u7b49\uff09\uff0c\u5219\u9700\u8981\u5bf9\u5176\u8fdb\u884c\u8f6c\u4e49\uff0c\u4ee5\u907f\u514d\u8f6c\u4e49\u5b57\u7b26\u9519\u8bef\u3002\u53ef\u4ee5\u4f7f\u7528 string.replace() \u65b9\u6cd5\u6216\u6b63\u5219\u8868\u8fbe\u5f0f\u6765\u8f6c\u4e49\u8fd9\u4e9b\u5b57\u7b26\u3002<\/p>\n<p>\u901a\u8fc7\u4e86\u89e3\u8fd9\u4e9b\u539f\u56e0\uff0c\u60a8\u53ef\u4ee5\u627e\u51fa\u5e76\u89e3\u51b3\u5bfc\u81f4 javascript \u4e2d alert \u4e2d\u6587\u4e71\u7801\u7684\u95ee\u9898\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fJavaScript \u4e2d alert \u4e2d\u6587\u4e71\u7801\u7684\u539f\u56e0\u6709\u54ea\u4e9b\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>javascript \u4e2d alert \u4e2d\u6587\u4e71\u7801\u63a2\u7a76 \u5728 javascript \u4e2d\uff0c\u6709\u65f6\u5728\u5c06\u4e2d\u6587\u6587\u672c\u8f93\u51fa\u5230 alert \u7a97\u53e3\u65f6\u4f1a\u9047\u5230\u4e2d\u6587\u4e71\u7801\u7684\u95ee\u9898\u3002\u8fd9\u53ef\u80fd\u662f\u7531\u4e8e\u4ee5\u4e0b\u539f\u56e0\u9020\u6210\u7684\uff1a 1. js \u6587\u4ef6\u7f16\u7801\u9519\u8bef \u786e\u4fdd js \u6587\u4ef6\u7684\u7f16\u7801\u65b9\u5f0f\u4e0e html \u6587\u4ef6\u7684\u7f16\u7801\u65b9\u5f0f\u4e00\u81f4\u3002\u4f8b\u5982\uff0c\u5982\u679c html \u6587\u4ef6\u4f7f\u7528 utf-8 \u7f16\u7801\uff0c\u5219 js \u6587\u4ef6\u4e5f\u5e94\u4f7f\u7528 utf-8 \u7f16\u7801\u3002 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b 2. \u5b57\u7b26\u4e32\u7f16\u7801\u4e0d\u5f53 \u76f4\u63a5\u5728 alert \u4e2d\u4f7f\u7528\u4e2d\u6587\u5b57\u7b26\u4e32\u53ef\u80fd\u4f1a\u5bfc\u81f4\u4e71\u7801\u3002\u53ef\u4ee5\u4f7f\u7528\u8f6c\u4e49\u5e8f\u5217\u6765\u6b63\u786e\u7f16\u7801\u5b57\u7b26\u4e32\uff0c\u4f8b\u5982\uff1a alert(&#8216;uesfa&#8217;); \u767b\u5f55\u540e\u590d\u5236 \u8fd9\u91cc\uff0c&#8217;uesfa&#8217; \u8868\u793a\u4e2d\u6587\u6c49\u5b57 &#8220;\u4e2d&#8221; \u7684 unicode \u7f16\u7801\u3002 3. \u811a\u672c\u6807\u7b7e charset \u8bbe\u7f6e\u65e0\u6548 \u5728 &lt;script&gt; \u6807\u7b7e\u4e2d\u8bbe\u7f6e charset \u5c5e\u6027\u53ef\u80fd\u65e0\u6548\uff0c\u56e0\u4e3a\u5b83\u4ec5\u9002\u7528\u4e8e\u5916\u90e8\u811a\u672c\u6587\u4ef6\u3002\u5bf9\u4e8e\u5d4c\u5165\u5f0f\u811a\u672c\uff0c\u5efa\u8bae\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\u6765\u8bbe\u7f6e\u7f16\u7801\uff1a&lt;\/script&gt; &lt;meta http-equiv=&#8221;Content-Type&#8221; content=&#8221;text\/html; charset=utf-8&#8243; \/&gt; \u767b\u5f55\u540e\u590d\u5236 4. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-1947","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1947","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=1947"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1947\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=1947"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=1947"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=1947"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}