{"id":3478,"date":"2024-11-10T08:20:21","date_gmt":"2024-11-10T00:20:21","guid":{"rendered":"https:\/\/fwq.ai\/blog\/3478\/"},"modified":"2024-11-10T08:20:21","modified_gmt":"2024-11-10T00:20:21","slug":"js%e5%a6%82%e4%bd%95%e8%be%93%e5%87%ba%e6%97%a5%e5%bf%97","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/3478\/","title":{"rendered":"js\u5982\u4f55\u8f93\u51fa\u65e5\u5fd7"},"content":{"rendered":"<blockquote><p>\n  \u5982\u4f55\u8f93\u51fa javascript \u65e5\u5fd7\uff1a\u4f7f\u7528 console \u5bf9\u8c61\uff0c\u63d0\u4f9b\u591a\u79cd\u8f93\u51fa\u7c7b\u578b\uff1aconsole.log()\uff1a\u4e00\u822c\u65e5\u5fd7console.info()\uff1a\u4fe1\u606f\u65e5\u5fd7console.warn()\uff1a\u8b66\u544a\u65e5\u5fd7console.error()\uff1a\u9519\u8bef\u65e5\u5fd7console.debug()\uff1a\u8c03\u8bd5\u65e5\u5fd7\uff08\u4ec5\u9650\u5f00\u53d1\u5de5\u5177\uff09\u67e5\u770b\u65e5\u5fd7\uff1a\u901a\u8fc7\u6d4f\u89c8\u5668\u7684\u5f00\u53d1\u5de5\u5177\uff08\u5982\u201c\u63a7\u5236\u53f0\u201d\u9009\u9879\u5361\uff09\u67e5\u770b\u3002\u683c\u5f0f\u5316\u65e5\u5fd7\uff1a\u4f7f\u7528 % \u8fd0\u7b97\u7b26\u8fdb\u884c\u683c\u5f0f\u5316\uff0c\u4ee5\u663e\u793a\u65e5\u5fd7\u7c7b\u578b\u548c\u65f6\u95f4\u6233\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/08\/2024110813163879559.jpg\" class=\"aligncenter\" title=\"js\u5982\u4f55\u8f93\u51fa\u65e5\u5fd7\u63d2\u56fe\" alt=\"js\u5982\u4f55\u8f93\u51fa\u65e5\u5fd7\u63d2\u56fe\" \/><\/p>\n<p><strong>JS\u5982\u4f55\u8f93\u51fa\u65e5\u5fd7<\/strong><\/p>\n<p>\u5728JavaScript\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u5185\u7f6e\u7684console\u5bf9\u8c61\u8f93\u51fa\u65e5\u5fd7\u4fe1\u606f\u3002console\u5bf9\u8c61\u63d0\u4f9b\u4e86\u591a\u79cd\u65b9\u6cd5\u6765\u8f93\u51fa\u4e0d\u540c\u7684\u65e5\u5fd7\u7c7b\u578b\uff0c\u5305\u62ec\uff1a<\/p>\n<ul>\n<li> <strong>console.log()\uff1a<\/strong>\u8f93\u51fa\u4e00\u822c\u65e5\u5fd7\u4fe1\u606f<\/li>\n<li> <strong>console.info()\uff1a<\/strong>\u8f93\u51fa\u4fe1\u606f\u6027\u65e5\u5fd7\u4fe1\u606f<\/li>\n<li> <strong>console.warn()\uff1a<\/strong>\u8f93\u51fa\u8b66\u544a\u65e5\u5fd7\u4fe1\u606f<\/li>\n<li> <strong>console.error()\uff1a<\/strong>\u8f93\u51fa\u9519\u8bef\u65e5\u5fd7\u4fe1\u606f<\/li>\n<li> <strong>console.debug()\uff1a<\/strong>\u8f93\u51fa\u8c03\u8bd5\u65e5\u5fd7\u4fe1\u606f\uff08\u4ec5\u5728\u6d4f\u89c8\u5668\u5f00\u53d1\u5de5\u5177\u4e2d\u53ef\u89c1\uff09<\/li>\n<\/ul>\n<p><strong>\u4f7f\u7528\u65b9\u6cd5\uff1a<\/strong><\/p>\n<p>\u4f7f\u7528console\u5bf9\u8c61\u8f93\u51fa\u65e5\u5fd7\u4fe1\u606f\uff0c\u53ea\u9700\u5c06\u65e5\u5fd7\u5185\u5bb9\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u7ed9\u76f8\u5e94\u7684console\u65b9\u6cd5\u5373\u53ef\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>\/\/ \u8f93\u51fa\u4e00\u822c\u65e5\u5fd7\u4fe1\u606f\nconsole.log(\"\u8fd9\u662f\u4e00\u6761\u65e5\u5fd7\u4fe1\u606f\");\n\n\/\/ \u8f93\u51fa\u8b66\u544a\u65e5\u5fd7\u4fe1\u606f\nconsole.warn(\"\u8fd9\u662f\u4e00\u4e2a\u8b66\u544a\");\n\n\/\/ \u8f93\u51fa\u9519\u8bef\u65e5\u5fd7\u4fe1\u606f\nconsole.error(\"\u8fd9\u662f\u4e00\u4e2a\u9519\u8bef\");<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u67e5\u770b\u65e5\u5fd7\uff1a<\/strong><\/p>\n<p>\u8f93\u51fa\u7684\u65e5\u5fd7\u4fe1\u606f\u53ef\u4ee5\u5728\u6d4f\u89c8\u5668\u7684\u5f00\u53d1\u5de5\u5177\u4e2d\u67e5\u770b\u3002\u901a\u5e38\uff0c\u53ef\u4ee5\u901a\u8fc7\u6309F12\u6216Ctrl + Shift + I\u6253\u5f00\u5f00\u53d1\u5de5\u5177\u3002\u5728\u5f00\u53d1\u5de5\u5177\u4e2d\uff0c\u53ef\u4ee5\u5728&#8221;Console&#8221;\u9009\u9879\u5361\u627e\u5230\u65e5\u5fd7\u8f93\u51fa\u3002<\/p>\n<p><strong>\u683c\u5f0f\u5316\u65e5\u5fd7\uff1a<\/strong><\/p>\n<p>\u4e3a\u4e86\u4f7f\u65e5\u5fd7\u4fe1\u606f\u66f4\u52a0\u76f4\u89c2\uff0c\u53ef\u4ee5\u5bf9\u65e5\u5fd7\u8fdb\u884c\u683c\u5f0f\u5316\u3002console\u5bf9\u8c61\u63d0\u4f9b\u4e86%\u8fd0\u7b97\u7b26\uff0c\u53ef\u4ee5\u7528\u4e8e\u5185\u5bb9\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>\/\/ \u683c\u5f0f\u5316\u65e5\u5fd7\uff0c\u663e\u793a\u65e5\u5fd7\u7c7b\u578b\u548c\u65f6\u95f4\u6233\nconsole.log(\"%c %s: %o\", \"color: red\", \"\u9519\u8bef\", new Error(\"\u9519\u8bef\u4fe1\u606f\"));<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u63d0\u793a\uff1a<\/strong><\/p>\n<ul>\n<li>\u5728\u5f00\u53d1\u548c\u8c03\u8bd5\u671f\u95f4\uff0c\u8f93\u51fa\u65e5\u5fd7\u4fe1\u606f\u975e\u5e38\u6709\u7528\u3002<\/li>\n<li>\u4f7f\u7528\u4e0d\u540c\u7684\u65e5\u5fd7\u7c7b\u578b\u53ef\u4ee5\u5e2e\u52a9\u533a\u5206\u4e0d\u540c\u7ea7\u522b\u7684\u4fe1\u606f\u3002<\/li>\n<li>\u907f\u514d\u8f93\u51fa\u8fc7\u4e8e\u8be6\u7ec6\u6216\u4e0d\u5fc5\u8981\u7684\u65e5\u5fd7\u4fe1\u606f\uff0c\u4ee5\u63d0\u9ad8\u5e94\u7528\u7a0b\u5e8f\u6027\u80fd\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fjs\u5982\u4f55\u8f93\u51fa\u65e5\u5fd7\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>\u5982\u4f55\u8f93\u51fa javascript \u65e5\u5fd7\uff1a\u4f7f\u7528 console \u5bf9\u8c61\uff0c\u63d0\u4f9b\u591a\u79cd\u8f93\u51fa\u7c7b\u578b\uff1aconsole.log()\uff1a\u4e00\u822c\u65e5\u5fd7console.info()\uff1a\u4fe1\u606f\u65e5\u5fd7console.warn()\uff1a\u8b66\u544a\u65e5\u5fd7console.error()\uff1a\u9519\u8bef\u65e5\u5fd7console.debug()\uff1a\u8c03\u8bd5\u65e5\u5fd7\uff08\u4ec5\u9650\u5f00\u53d1\u5de5\u5177\uff09\u67e5\u770b\u65e5\u5fd7\uff1a\u901a\u8fc7\u6d4f\u89c8\u5668\u7684\u5f00\u53d1\u5de5\u5177\uff08\u5982\u201c\u63a7\u5236\u53f0\u201d\u9009\u9879\u5361\uff09\u67e5\u770b\u3002\u683c\u5f0f\u5316\u65e5\u5fd7\uff1a\u4f7f\u7528 % \u8fd0\u7b97\u7b26\u8fdb\u884c\u683c\u5f0f\u5316\uff0c\u4ee5\u663e\u793a\u65e5\u5fd7\u7c7b\u578b\u548c\u65f6\u95f4\u6233\u3002 JS\u5982\u4f55\u8f93\u51fa\u65e5\u5fd7 \u5728JavaScript\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u5185\u7f6e\u7684console\u5bf9\u8c61\u8f93\u51fa\u65e5\u5fd7\u4fe1\u606f\u3002console\u5bf9\u8c61\u63d0\u4f9b\u4e86\u591a\u79cd\u65b9\u6cd5\u6765\u8f93\u51fa\u4e0d\u540c\u7684\u65e5\u5fd7\u7c7b\u578b\uff0c\u5305\u62ec\uff1a console.log()\uff1a\u8f93\u51fa\u4e00\u822c\u65e5\u5fd7\u4fe1\u606f console.info()\uff1a\u8f93\u51fa\u4fe1\u606f\u6027\u65e5\u5fd7\u4fe1\u606f console.warn()\uff1a\u8f93\u51fa\u8b66\u544a\u65e5\u5fd7\u4fe1\u606f console.error()\uff1a\u8f93\u51fa\u9519\u8bef\u65e5\u5fd7\u4fe1\u606f console.debug()\uff1a\u8f93\u51fa\u8c03\u8bd5\u65e5\u5fd7\u4fe1\u606f\uff08\u4ec5\u5728\u6d4f\u89c8\u5668\u5f00\u53d1\u5de5\u5177\u4e2d\u53ef\u89c1\uff09 \u4f7f\u7528\u65b9\u6cd5\uff1a \u4f7f\u7528console\u5bf9\u8c61\u8f93\u51fa\u65e5\u5fd7\u4fe1\u606f\uff0c\u53ea\u9700\u5c06\u65e5\u5fd7\u5185\u5bb9\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u7ed9\u76f8\u5e94\u7684console\u65b9\u6cd5\u5373\u53ef\u3002\u4f8b\u5982\uff1a \/\/ \u8f93\u51fa\u4e00\u822c\u65e5\u5fd7\u4fe1\u606f console.log(&#8220;\u8fd9\u662f\u4e00\u6761\u65e5\u5fd7\u4fe1\u606f&#8221;); \/\/ \u8f93\u51fa\u8b66\u544a\u65e5\u5fd7\u4fe1\u606f console.warn(&#8220;\u8fd9\u662f\u4e00\u4e2a\u8b66\u544a&#8221;); \/\/ \u8f93\u51fa\u9519\u8bef\u65e5\u5fd7\u4fe1\u606f console.error(&#8220;\u8fd9\u662f\u4e00\u4e2a\u9519\u8bef&#8221;); \u767b\u5f55\u540e\u590d\u5236 \u67e5\u770b\u65e5\u5fd7\uff1a \u8f93\u51fa\u7684\u65e5\u5fd7\u4fe1\u606f\u53ef\u4ee5\u5728\u6d4f\u89c8\u5668\u7684\u5f00\u53d1\u5de5\u5177\u4e2d\u67e5\u770b\u3002\u901a\u5e38\uff0c\u53ef\u4ee5\u901a\u8fc7\u6309F12\u6216Ctrl + Shift + I\u6253\u5f00\u5f00\u53d1\u5de5\u5177\u3002\u5728\u5f00\u53d1\u5de5\u5177\u4e2d\uff0c\u53ef\u4ee5\u5728&#8221;Console&#8221;\u9009\u9879\u5361\u627e\u5230\u65e5\u5fd7\u8f93\u51fa\u3002 \u683c\u5f0f\u5316\u65e5\u5fd7\uff1a \u4e3a\u4e86\u4f7f\u65e5\u5fd7\u4fe1\u606f\u66f4\u52a0\u76f4\u89c2\uff0c\u53ef\u4ee5\u5bf9\u65e5\u5fd7\u8fdb\u884c\u683c\u5f0f\u5316\u3002console\u5bf9\u8c61\u63d0\u4f9b\u4e86%\u8fd0\u7b97\u7b26\uff0c\u53ef\u4ee5\u7528\u4e8e\u5185\u5bb9\u3002\u4f8b\u5982\uff1a \/\/ \u683c\u5f0f\u5316\u65e5\u5fd7\uff0c\u663e\u793a\u65e5\u5fd7\u7c7b\u578b\u548c\u65f6\u95f4\u6233 console.log(&#8220;%c %s: %o&#8221;, &#8220;color: red&#8221;, &#8220;\u9519\u8bef&#8221;, new Error(&#8220;\u9519\u8bef\u4fe1\u606f&#8221;)); \u767b\u5f55\u540e\u590d\u5236 \u63d0\u793a\uff1a \u5728\u5f00\u53d1\u548c\u8c03\u8bd5\u671f\u95f4\uff0c\u8f93\u51fa\u65e5\u5fd7\u4fe1\u606f\u975e\u5e38\u6709\u7528\u3002 \u4f7f\u7528\u4e0d\u540c\u7684\u65e5\u5fd7\u7c7b\u578b\u53ef\u4ee5\u5e2e\u52a9\u533a\u5206\u4e0d\u540c\u7ea7\u522b\u7684\u4fe1\u606f\u3002 \u907f\u514d\u8f93\u51fa\u8fc7\u4e8e\u8be6\u7ec6\u6216\u4e0d\u5fc5\u8981\u7684\u65e5\u5fd7\u4fe1\u606f\uff0c\u4ee5\u63d0\u9ad8\u5e94\u7528\u7a0b\u5e8f\u6027\u80fd\u3002 \u4ee5\u4e0a\u5c31\u662fjs\u5982\u4f55\u8f93\u51fa\u65e5\u5fd7\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/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-3478","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3478","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=3478"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3478\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=3478"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=3478"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=3478"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}