{"id":105,"date":"2007-01-31T13:28:55","date_gmt":"2007-01-31T05:28:55","guid":{"rendered":"http:\/\/tmp.xujiwei.com\/blog\/?p=105"},"modified":"2010-01-29T00:03:15","modified_gmt":"2010-01-28T16:03:15","slug":"using-window-onload-or-other","status":"publish","type":"post","link":"https:\/\/xujiwei.com\/blog\/2007\/01\/using-window-onload-or-other\/","title":{"rendered":"\u8bbe\u8ba1\u7684\u9009\u62e9\uff1awindow.onload or other"},"content":{"rendered":"<p>\u5728\u7f51\u9875\u8bbe\u8ba1\u4e2d\uff0c\u603b\u8981\u7528\u5230\u4e00\u4e9b\u52a8\u6001\u6548\u679c\uff0c\u800c\u8fd9\u4e9b\u6548\u679c\u4e4b\u4e2d\uff0c\u6709\u4e00\u4e9b\u662f\u9700\u8981\u9875\u9762\u52a0\u8f7d\u5b8c\u6210\u65f6\u624d\u53ef\u4ee5\u505a\u7684\uff0c\u6bd4\u5982\u8981\u7ed9\u9875\u9762\u4e2d\u7684\u6bcf\u4e00\u4e2a\u94fe\u63a5\u52a0\u4e0ahover\u65f6\u7684\u7279\u6548\uff0c\u90a3\u4e48\u5c31\u9700\u8981\u5728\u9875\u9762\u7684\u6240\u6709\u4ee3\u7801\u5df2\u7ecf\u4e0b\u8f7d\u5b8c\u6bd5\u65f6\u518d\u8fdb\u884c\u7279\u6548\uff0c\u8fd9\u6837\u624d\u80fd\u4fdd\u8bc1\u9875\u9762\u91cc\u7684\u6bcf\u4e00\u4e2a\u94fe\u63a5\u90fd\u4e0d\u4f1a\u9057\u6f0f\u3002\u5982\u679c\u8fd9\u6b65\u5de5\u4f5c\u653e\u5728head\u4e2d\uff0c\u90a3\u4e48\uff0c\u505a\u4e0e\u4e0d\u505a\u4e00\u4e2a\u6837\u3002<\/p>\n<p>\u518d\u8005\uff0c\u73b0\u5728\u7f51\u9875\u8bbe\u8ba1\u8bb2\u7a76\u884c\u4e3a\u3001\u7ed3\u6784\u3001\u8868\u73b0\u5206\u79bb\uff0c\u6bd4\u5982\u5728\u6700\u8fd1\u7684\u4e00\u6b21\u6539\u7248\u4e2d\uff0c\u6211\u628a<a rel=\"external\" href=\"http:\/\/www.xujiwei.cn\/blog\/\">\u6211\u7684blog<\/a>\u4fa7\u8fb9\u680f\u7684\u5c55\u5f00\u4e0e\u6298\u53e0\u7684\u529f\u80fd\u653e\u5728\u4e86JS\u4e2d\u6dfb\u52a0\uff0c\u5e76\u4e0d\u662f\u5728\u6e90\u4ee3\u7801\u91cc\u76f4\u63a5\u8bbe\u7f6eonclick\u4e8b\u4ef6\u6dfb\u52a0\u597d\u7684\u3002\u56e0\u4e3a\u51fd\u6570\u8c03\u7528\u4e0d\u662f\u76f4\u63a5\u76f4\u63a5\u800c\u662f\u540e\u6765\u6dfb\u52a0\u7684\uff0c\u6211\u5c31\u8981\u8003\u8651\u4ec0\u4e48\u65f6\u5019\u6765\u7528JS\u6dfb\u52a0\u4fa7\u8fb9\u680f\u7684\u5c55\u5f00\u4e0e\u6298\u53e0\u4e86\u3002<\/p>\n<p>\u529f\u80fd\u7684\u6dfb\u52a0\u51fd\u6570\u6240\u5728\u7684\u811a\u672c\u653e\u5728\u4e86head\u533a\u5f15\u5165\uff0c\u5f53\u7136\u4e0d\u80fd\u5728\u811a\u672c\u91cc\u76f4\u63a5\u8c03\u7528\u8fd9\u4e2a\u51fd\u6570\u6765\u8fdb\u884c\u529f\u80fd\u7684\u6dfb\u52a0\uff0c\u56e0\u4e3a\u90a3\u4e2a\u65f6\u5019\u8fb9\u680f\u8fd8\u6ca1\u6709\u52a0\u8f7d\uff0c\u7528document.getElementById\u4f1a\u51fa\u73b0\u627e\u4e0d\u5230\u5bf9\u8c61\u7684\u9519\u8bef\uff0c\u7136\u540e\u8fb9\u680f\u7684\u5c55\u5f00\u4e0e\u6298\u53e0\u529f\u80fd\u5c31\u6ca1\u6709\u3002<\/p>\n<p>\u90a3\u4e48\uff0c\u4ece\u8fd9\u4e00\u70b9\u77e5\u9053\uff0c<strong>\u529f\u80fd\u7684\u6dfb\u52a0\u662f\u9700\u8981\u5728\u8981\u5904\u7406\u7684\u5185\u5bb9\u5df2\u7ecf\u52a0\u8f7d\u5b8c\u6210\u7684\u60c5\u51b5\u4e0b\u624d\u80fd\u6dfb\u52a0<\/strong>\u3002<\/p>\n<p>\u90a3\u4ec0\u4e48\u65f6\u5019\u4fa7\u8fb9\u680f\u5df2\u7ecf\u52a0\u8f7d\u5b8c\u6bd5\u4e86\u5462\uff0c\u8bb8\u591a\u4eba\u81ea\u7136\u800c\u7136\u5730\u5c31\u60f3\u5230\u4e86window.onload\u3002\u662f\u7684\uff0c\u5728window.onload\u88ab\u8c03\u7528\u65f6\uff0c\u6574\u4e2a\u9875\u9762\u5df2\u7ecf\u52a0\u8f7d\u5b8c\u6210\uff0c\u90a3\u4e48\u8fb9\u680f\u4e5f\u4e00\u5b9a\u52a0\u8f7d\u5b8c\u6bd5\uff0c\u8fd9\u4e2a\u65f6\u5019\u505a\u6dfb\u52a0onclick\u54cd\u5e94\u51fd\u6570\u662f\u80af\u5b9a\u4e0d\u4f1a\u51fa\u73b0\u627e\u4e0d\u5230\u5bf9\u8c61\u7684\u9519\u8bef\u7684\u3002<\/p>\n<blockquote>\n<div id=\"_mcePaste\">\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">&lt;html&gt;<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">&lt;head&gt;<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> &lt;meta name=\"author\" content=\"www.xujiwei.cn\" \/&gt;<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> &lt;meta name=\"description\" content=\"ue test from xujiwei\" \/&gt;<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> &lt;title&gt;ue test1&lt;\/title&gt;<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> &lt;style type=\"text\/css\"&gt;<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> #blockHead {<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> background: blue; color: white; width: 300px; padding: 1em; cursor: pointer; border: 1px solid blue;<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> }<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> #blockContent {<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> border: 1px solid blue; width: 300px; padding: 1em;<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> }<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> &lt;\/style&gt;<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> &lt;script type=\"text\/javascript\"&gt;<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> window.onload=function() {<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> document.getElementById(\"blockHead\").onclick=function() {<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> if(document.getElementById(\"blockContent\").style.display==\"\")<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> document.getElementById(\"blockContent\").style.display=\"none\";<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> else<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> document.getElementById(\"blockContent\").style.display=\"\";<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> }<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> }<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> &lt;\/script&gt;<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">&lt;\/head&gt;<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">&lt;body&gt;<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">&lt;div id=\"blockHead\"&gt;block Head&lt;\/div&gt;<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">&lt;div id=\"blockContent\"&gt;&lt;img src=\"http:\/\/www.xujiwei.cn\/logo.gif\" alt=\"hotheart\" \/&gt;block Content&lt;\/div&gt;<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">&lt;\/body&gt;<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">&lt;\/html&gt;<\/span><\/div>\n<\/div>\n<\/blockquote>\n<p><span style=\"color: #333333; font-family: Corbel, \u5fae\u8f6f\u96c5\u9ed1, Verdana, Arial, sans-serif; line-height: 21px; font-size: 14px;\"> <\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\">\u5982\u6b64\uff0c\u4fbf\u7ed9\u8fb9\u680f\u7684Member\u6a21\u5757\u52a0\u4e0a\u4e86\u6298\u53e0\u529f\u80fd\u3002\u4f46\u662f\uff0conload\u4f1a\u662f\u6700\u597d\u7684\u9009\u62e9\u5417\uff1f<\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\">\u56de\u7b54\u662f\u5426\u5b9a\u7684\uff0c\u4e3a\u4ec0\u4e48\uff0c\u56e0\u4e3a<strong>window.onload\u53ea\u6709\u5728\u6574\u4e2a\u9875\u9762\u5b8c\u5168\u52a0\u8f7d\u5b8c\u6210\uff0c\u5305\u62ec\u4e00\u4e9b\u56e0\u4e3a\u7f51\u901f\u6216\u8005\u94fe\u63a5\u5931\u6548\u7684\u5185\u5bb9\u4e5f\u5168\u90e8\u52a0\u8f7d\u5b8c\u6210\u6216\u8005\u786e\u8ba4\u65e0\u6548\u65f6\u624d\u4f1a\u88ab\u8c03\u7528<\/strong>\u3002\u90a3\u4e48\uff0c\u4e07\u4e00\uff0c\u5982\u679c\u8fd9\u4e2a\u9875\u9762\u91cc\u6709\u67d0\u4e9b\u5143\u7d20\u7531\u4e8e\u67d0\u4e9b\u539f\u56e0\u800c\u5f97\u4e0d\u5230\u53ca\u65f6\u7684\u52a0\u8f7d\uff0c\u5c31\u4f1a\u5ef6\u957f\u6574\u4e2a\u9875\u9762\u7684\u52a0\u8f7d\u65f6\u95f4\uff0cwindow.onload\u7684\u6267\u884c\u65f6\u523b\u4e5f\u4f1a\u76f8\u5e94\u7684\u5f80\u540e\u79fb\u3002\u8b6c\u5982\u4e0b\u9762\u8fd9\u6bb5\uff1a<\/p>\n<blockquote>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\">\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\">&lt;html&gt;<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\">&lt;head&gt;<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\"> &lt;meta name=\"author\" content=\"www.xujiwei.cn\" \/&gt;<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\"> &lt;meta name=\"description\" content=\"ue test from xujiwei\" \/&gt;<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\"> &lt;title&gt;ue test2&lt;\/title&gt;<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\"> &lt;style type=\"text\/css\"&gt;<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\"> #blockHead {<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\"> background: blue; color: white; width: 300px; padding: 1em; cursor: pointer; border: 1px solid blue;<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\"> }<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\"> #blockContent {<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\"> border: 1px solid blue; width: 300px; padding: 1em;<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\"> }<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\"> &lt;\/style&gt;<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\"> &lt;script type=\"text\/javascript\"&gt;<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\"> window.onload=function() {<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\"> document.getElementById(\"blockHead\").onclick=function() {<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\"> if(document.getElementById(\"blockContent\").style.display==\"\")<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\"> document.getElementById(\"blockContent\").style.display=\"none\";<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\"> else<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\"> document.getElementById(\"blockContent\").style.display=\"\";<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\"> }<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\"> }<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\"> &lt;\/script&gt;<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\">&lt;\/head&gt;<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\">&lt;body&gt;<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\">&lt;div id=\"blockHead\"&gt;block Head&lt;\/div&gt;<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\">&lt;div id=\"blockContent\"&gt;&lt;img src=\"http:\/\/www.xujiwei.c_n\/logo.gif\" alt=\"hotheart\" \/&gt;block Content&lt;\/div&gt;<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\">&lt;\/body&gt;<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\">&lt;\/html&gt;<\/span><\/p>\n<\/blockquote>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\"> <span style=\"color: #333333; font-family: Corbel, \u5fae\u8f6f\u96c5\u9ed1, Verdana, Arial, sans-serif; line-height: 21px; font-size: 14px;\">\u56e0\u4e3ahttp:\/\/www.xujiwei.c_n\/logo.gif\u4e2d\u7684\u57df\u540d\u662f\u4e0d\u5408\u6cd5\u7684\uff08\u57df\u540d\u4e2d\u4e0d\u53ef\u4ee5\u5305\u542b\u4e0b\u5212\u7ebf\uff09\uff0c\u4f46\u662f\u6d4f\u89c8\u5668\u4e0d\u4f1a\u53bb\u5224\u65ad\uff0c\u4ecd\u65e7\u7167\u5e38\u53bb\u89e3\u6790\uff0c\u7136\u540e\u51fa\u73b0\u4e0d\u53ef\u5230\u8fbe\u7684\u9519\u8bef\uff0c\u518d\u7528\u56fe\u7247\u7684\u66ff\u4ee3\u6587\u672c\u6765\u4ee3\u66ff\u56fe\u7247\uff0c\u8fd9\u9700\u8981\u65f6\u95f4\u3002<strong>\u5728\u8fd9\u6bb5\u65f6\u95f4\u91cc\uff0cwindow.onload\u90fd\u4e0d\u4f1a\u6267\u884c\uff0c\u56e0\u4e3a\u6d4f\u89c8\u5668\u8ba4\u4e3a\u9875\u9762\u8fd8\u6ca1\u6709\u52a0\u8f7d\u5b8c\u6210\uff0c\u6240\u4ee5\u8fd8\u4e0d\u662f\u8c03\u7528window.onload\u7684\u65f6\u5019\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u8fd9\u4e2a\u6298\u53e0\u529f\u80fd\u4e00\u76f4\u6ca1\u6709\u6dfb\u52a0<\/strong>\u3002<\/span><\/span><\/p>\n<p><span style=\"color: #333333; font-family: Corbel, \u5fae\u8f6f\u96c5\u9ed1, Verdana, Arial, sans-serif; line-height: 21px; font-size: 14px;\"> <\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\">\u4f46\u662f\u7528\u6237\u7684\u64cd\u4f5c\u4e0d\u4f1a\u53d7\u8fd9\u4e00\u70b9\u5185\u5bb9\u7684\u5f71\u54cd\u3002\u5728\u6574\u4e2a\u9875\u9762\u7684\u8f6e\u5ed3\u51fa\u6765\u4ee5\u540e\uff0c\u7528\u6237\u5c31\u4f1a\u5f00\u59cb\u505a\u81ea\u5df1\u8981\u505a\u7684\u4e8b\uff0c\u800c\u4e0d\u4f1a\u7b49\u5230\u6d4f\u89c8\u5668\u786e\u8ba4\u90a3\u4e00\u70b9\u70b9\u7684\u4e1c\u897f\u662f\u4e0d\u53ef\u4ee5\u6210\u529f\u52a0\u8f7d\u7684\uff0c\u6267\u884c\u5b8cwindow.onload\u624d\u53bb\u505a\u81ea\u5df1\u8981\u505a\u7684\u4e8b\u3002<\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\">\u6362\u53e5\u8bdd\u8bf4\uff0c\u5c31\u662f\u8fd9\u4e9b<strong>\u529f\u80fd\u7684\u6dfb\u52a0\u8981\u5728\u7528\u6237\u89c9\u5f97\u4ed6\u53ef\u4ee5\u505a\u4ed6\u81ea\u5df1\u8981\u505a\u7684\u4e8b\u4e4b\u524d\u8fdb\u884c\uff0c\u4e2d\u95f4\u4e0d\u80fd\u56e0\u4e3a\u4e00\u4e9b\u672a\u77e5\u7684\u539f\u56e0\u800c\u6401\u7f6e<\/strong>\u3002\u90a3\u4e48\uff0c\u8fd9\u4e9b\u529f\u80fd\u7684\u6dfb\u52a0\u5e94\u8be5\u653e\u5728\u4ec0\u4e48\u4f4d\u7f6e\uff1f\u6211\u7684\u505a\u6cd5\u662f\u5728\u9875\u9762\u7684HTML\u5df2\u7ecf\u8f7d\u5165\u65f6\u53bb\u8c03\u7528\u529f\u80fd\u6dfb\u52a0\u51fd\u6570\uff0c\u518d\u52a0\u4e0aHTML\u8bed\u6cd5\u89c4\u5219\uff0c\u628a\u529f\u80fd\u6dfb\u52a0\u51fd\u6570\u7684\u8c03\u7528\u653e\u5728\u4e86body\u6807\u7b7e\u7ed3\u675f\u4e4b\u524d\uff0c\u5373\uff1a<\/p>\n<blockquote>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\">\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\">&lt;html&gt;<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\">&lt;head&gt;<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\"> &lt;meta name=\"author\" content=\"www.xujiwei.cn\" \/&gt;<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\"> &lt;meta name=\"description\" content=\"ue test from xujiwei\" \/&gt;<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\"> &lt;title&gt;ue test3&lt;\/title&gt;<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\"> &lt;style type=\"text\/css\"&gt;<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\"> #blockHead {<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\"> background: blue; color: white; width: 300px; padding: 1em; cursor: pointer; border: 1px solid blue;<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\"> }<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\"> #blockContent {<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\"> border: 1px solid blue; width: 300px; padding: 1em;<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\"> }<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\"> &lt;\/style&gt;<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\"> &lt;script type=\"text\/javascript\"&gt;<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\"> function initApp() {<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\"> document.getElementById(\"blockHead\").onclick=function() {<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\"> if(document.getElementById(\"blockContent\").style.display==\"\")<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\"> document.getElementById(\"blockContent\").style.display=\"none\";<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\"> else<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\"> document.getElementById(\"blockContent\").style.display=\"\";<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\"> }<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\"> }<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\"> &lt;\/script&gt;<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\">&lt;\/head&gt;<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\">&lt;body&gt;<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\">&lt;div id=\"blockHead\"&gt;block Head&lt;\/div&gt;<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\">&lt;div id=\"blockContent\"&gt;&lt;img src=\"http:\/\/www.xujiwei.c_n\/logo.gif\" alt=\"hotheart\" \/&gt;block Content&lt;\/div&gt;<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\">&lt;script type=\"text\/javascript\"&gt;<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\"> initApp();<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\">&lt;\/script&gt;<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\">&lt;\/body&gt;<\/span><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\"><span style=\"font-style: normal;\">&lt;\/html&gt;<\/span><\/p>\n<\/blockquote>\n<p><span style=\"color: #333333; font-family: Corbel, \u5fae\u8f6f\u96c5\u9ed1, Verdana, Arial, sans-serif; line-height: 21px; font-size: 14px;\"><\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\">\u8fd9\u4e2a\u65f6\u5019\uff0c\u867d\u7136\u6d4f\u89c8\u5668\u4ecd\u7136\u5728\u8bd5\u56fe\u89e3\u6790www.xujiwei.c_n\uff0c\u53bb\u4e0b\u8f7dlogo.gif\uff0c\u4f46\u662f\u6298\u53e0\u529f\u80fd\u5df2\u7ecf\u6210\u529f\u6dfb\u52a0\u4e86\uff0c\u7528\u6237\u8fdb\u884c\u4ed6\u7684\u64cd\u4f5c\u5df2\u7ecf\u6ca1\u6709\u95ee\u9898\uff0c\u81f3\u4e8e\u90a3\u5f20\u56fe\u7247\u662f\u5426\u80fd\u663e\u793a\u51fa\u6765\uff0c\u5df2\u7ecf\u4e0d\u4f1a\u5f71\u54cd\u7528\u6237\u5bf9\u6574\u4e2a\u9875\u9762\u7684\u4f7f\u7528\u3002<\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\">\u5728test1\u4e2d\uff0c\u53ef\u4ee5\u770b\u51fa\u5982\u679c\u6574\u4f53\u9875\u9762\u4e2d\u6ca1\u6709\u5f71\u54cd\u9875\u9762\u52a0\u8f7d\u7684\u5185\u5bb9\uff0c\u90a3\u4e48window.onload\u8fdb\u884c\u9875\u9762\u529f\u80fd\u6dfb\u52a0\u4e5f\u662f\u53ef\u4ee5\u7684\uff0c\u4f46\u662f\u73b0\u5728\u7684\u7f51\u9875\u505a\u51fa\u6765\u8c01\u80fd\u4fdd\u8bc1\u5176\u4e2d\u7684\u5185\u5bb9\u4e00\u76f4\u6709\u6548\u5462\uff0c\u4e8e\u662f\u5728test2\u4e2d\u53ef\u4ee5\u770b\u5230\u5982\u679c\u9875\u9762\u4e2d\u6709\u52a0\u8f7d\u4e0d\u4e86\u7684\u5185\u5bb9\uff0cwindow.onload\u53ef\u80fd\u4f1a\u5728\u7528\u6237\u79bb\u5f00\u9875\u9762\u4e4b\u540e\u8fd8\u6ca1\u6709\u6267\u884c\uff0c\u5c31\u56e0\u4e3a\u90a3\u4e48\u4e00\u70b9\u5185\u5bb9\u52a0\u8f7d\u4e0d\u4e86\uff0c\u5bfc\u81f4window.onload\u4e0d\u80fd\u6267\u884c\uff0c\u63a5\u7740\u5c31\u662f\u4e00\u4e9b\u529f\u80fd\u7528\u6237\u4e0d\u80fd\u7528\uff0c\u63a5\u7740\u7528\u6237\u611f\u89c9\u5c31\u4e0d\u597d\uff0c\u63a5\u7740\u7528\u6237\u5c31\u79bb\u5f00\u4e86\u672c\u9875\u3002\u800c\u5728test3\u4e2d\uff0c\u6ca1\u6709\u628a\u529f\u80fd\u7684\u6dfb\u52a0\u653e\u5728window.onload\u4e2d\uff0c\u800c\u662f\u653e\u5728\u4e86\u9875\u9762\u4ee3\u7801\u7684\u672b\u5c3e\uff0c\u90a3\u4e48\u5373\u4e0d\u4f1a\u5728\u6267\u884c\u529f\u80fd\u6dfb\u52a0\u51fd\u6570\u65f6\uff0c\u51fa\u73b0\u627e\u4e0d\u5230\u5bf9\u8c61\u7684\u9519\u8bef\uff0c\u4e5f\u4e0d\u4f1a\u56e0\u4e3a\u9875\u9762\u4e00\u70b9\u52a0\u8f7d\u4e0d\u4e86\u7684\u5185\u5bb9\u800c\u5f71\u54cd\u529f\u80fd\u7684\u6dfb\u52a0\uff0c\u7528\u6237\u80fd\u611f\u89c9\u5230\u7684\u53ea\u662f\u6709\u90a3\u4e48\u4e00\u70b9\u70b9\u5185\u5bb9\u53ef\u80fd\u56e0\u4e3a\u65f6\u95f4\u6216\u8005\u5176\u4ed6\u4e00\u4e9b\u539f\u56e0\u5931\u6548\u800c\u4e0d\u80fd\u52a0\u8f7d\uff0c\u4f46\u8fd9\u5e76\u4e0d\u5f71\u54cd\u4ed6\u5bf9\u6574\u4e2a\u9875\u9762\u7684\u4f7f\u7528\u3002<\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\">\u5f53\u7136\uff0c\u9009\u62e9\u5728\u54ea\u4e2a\u5730\u65b9\u8fdb\u884c\u9875\u9762\u529f\u80fd\u7684\u6dfb\u52a0\u662f\u4e2a\u4ec1\u8005\u89c1\u4ec1\uff0c\u667a\u8005\u89c1\u667a\u7684\u95ee\u9898\u3002\u6bcf\u4e2a\u4eba\u7684\u9700\u8981\u4e0d\u540c\uff0c\u5904\u7406\u65b9\u6cd5\u4e5f\u4f1a\u76f8\u5e94\u7684\u4e0d\u540c\u3002\u6211\u6bd4\u8f83\u503e\u5411\u4e8e\u628a\u9875\u9762\u4e2d\u5173\u952e\u529f\u80fd\u7684\u90e8\u5206\u653e\u5728body\u7ed3\u675f\u6807\u7b7e\u4e4b\u524d\uff0c\u800c\u5176\u4ed6\u4e00\u4e9b\u4fee\u9970\u6027\u7684\u529f\u80fd\u5982\u679c\u7ed9\u94fe\u63a5\u52a0\u4e0a\u4fee\u9970\u6027\u7684title\u7b49\u653e\u5728window.onload\uff0c\u8fd9\u6837\u5373\u4e0d\u4f1a\u5f71\u54cd\u4f7f\u7528\u53c8\u80fd\u6709\u8f83\u597d\u7684\u9875\u9762\u6548\u679c\u3002<\/p>\n<p style=\"margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.7em; margin-left: 0px; text-indent: 2em; line-height: 1.5em; padding: 0px;\">\u5982\u679c\u5927\u5bb6\u6709\u4ec0\u4e48\u597d\u7684\u60f3\u6cd5\u53ef\u4ee5\u4e00\u8d77\u8ba8\u8bba\uff0c\u6211\u7684\u90ae\u7bb1vipxjw[at]163[dot]com\u3002<\/p>\n<p><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u7f51\u9875\u8bbe\u8ba1\u4e2d\uff0c\u603b\u8981\u7528\u5230\u4e00\u4e9b\u52a8\u6001\u6548\u679c\uff0c\u800c\u8fd9\u4e9b\u6548\u679c\u4e4b\u4e2d\uff0c\u6709\u4e00\u4e9b\u662f\u9700\u8981\u9875\u9762\u52a0\u8f7d\u5b8c\u6210\u65f6\u624d &hellip;<\/p>\n<p class=\"read-more\"><a href=\"https:\/\/xujiwei.com\/blog\/2007\/01\/using-window-onload-or-other\/\">\u7ee7\u7eed\u9605\u8bfb &raquo;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[11],"tags":[72,73,74],"_links":{"self":[{"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/posts\/105"}],"collection":[{"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/comments?post=105"}],"version-history":[{"count":0,"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/posts\/105\/revisions"}],"wp:attachment":[{"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/media?parent=105"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/categories?post=105"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/tags?post=105"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}