{"id":211487,"date":"2021-02-26T10:46:29","date_gmt":"2021-02-26T02:46:29","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=211487"},"modified":"2021-02-20T09:39:05","modified_gmt":"2021-02-20T01:39:05","slug":"js-windows-onload","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/js-windows-onload.html","title":{"rendered":"JavaScript window.onload\u7b80\u4ecb"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nwindow.onload\uff08\uff09\u65b9\u6cd5\u7528\u4e8e\u5728\u7f51\u9875\u52a0\u8f7d\u5b8c\u6210\u540e\u7acb\u5373\u6267\u884c\u7684\u64cd\u4f5c\uff0c\u5373\u5f53HTML\u6587\u6863\u52a0\u8f7d\u5b8c\u6210\u540e\uff0c\u7acb\u5373\u6267\u884c\u67d0\u4e2a\u65b9\u6cd5\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

window.onload\uff08\uff09\u901a\u5e38\u7528\u4e8e

彩票走势图

\u5143\u7d20\uff0c\u5728\u9875\u9762\u5b8c\u5168\u52a0\u8f7d\u540e\uff08\u5305\u62ec\u56fe\u7247\uff0ccss\u6587\u4ef6\u7b49\u7b49\uff09\u6267\u884c\u811a\u672c\u4ee3\u7801\u3002<\/p>\n

\u53ea\u6709\u4e00\u4e2a\u8981\u6267\u884c\u7684\u51fd\u6570\u8bed\u6cd5\uff1a<\/p>\n

\u7a97\u53e3\u3002onload = funcRef ;<\/pre>\n

\u5728\u9875\u9762\u52a0\u8f7d\u5b8c\u6210\u540efuncRef\u65b9\u6cd5\u4f1a\u88ab\u8c03\u7528\u3002<\/p>\n

\u6709\u591a\u4e2a\u8981\u6267\u884c\u7684\u51fd\u6570\u8bed\u6cd5\uff1a<\/p>\n

\u7a97\u53e3\u3002onload = function \uff08\uff09{ Func1 \uff08\uff09; Func2 \uff08\uff09; Func3 \uff08\uff09; ..... }<\/pre>\n

\u5728\u9875\u9762\u52a0\u8f7d\u5b8c\u6210\u540e\u4f9d\u6b21\u6267\u884cFunc1\uff0cFunc2\uff0cFunc3\u3002<\/p>\n

\u4e3a\u4ec0\u4e48\u4f7f\u7528 window.onload()?<\/strong><\/div>\n

\u56e0\u4e3a JavaScript \u4e2d\u7684\u51fd\u6570\u65b9\u6cd5\u9700\u8981\u5728 HTML \u6587\u6863\u6e32\u67d3\u5b8c\u6210\u540e\u624d\u53ef\u4ee5\u4f7f\u7528\uff0c\u5982\u679c\u6ca1\u6709\u6e32\u67d3\u5b8c\u6210\uff0c\u6b64\u65f6\u7684 DOM \u6811\u662f\u4e0d\u5b8c\u6574\u7684\uff0c\u8fd9\u6837\u5728\u8c03\u7528\u4e00\u4e9b JavaScript \u4ee3\u7801\u65f6\u5c31\u53ef\u80fd\u62a5\u51fa\"undefined\"\u9519\u8bef\u3002<\/p>\n

\u5b9e\u4f8b<\/strong><\/p>\n

<<\/span>!<\/span>DOCTYPE<\/span> <\/span>html<\/span>><\/span> \r\n<\/span><<\/span>html<\/span>><\/span> \r\n<\/span><<\/span>head<\/span>><\/span> \r\n<\/span><<\/span>meta<\/span> <\/span>charset<\/span>=<\/span>\"<\/span> utf-8<\/span>\"<\/span>><\/span> \r\n<\/span><<\/span>title<\/span>><\/span>\u6ca1\u6709\u4f7f\u7528 window.onload() \u6d4b\u8bd5<\/span><\/<\/span>title<\/span>><\/span>\r\n<\/span><<\/span>style<\/span> <\/span>type<\/span>=<\/span>\"<\/span>text\/css<\/span>\"<\/span>><\/span>\r\n#bg{\r\n width:120px;\r\n height:120px;\r\n border:4px solid blue;\r\n}\r\n<\/span><\/<\/span>style<\/span>><\/span>\r\n<\/span><<\/span>script<\/span> <\/span>type<\/span>=<\/span>\"<\/span>text\/javascript<\/span>\"<\/span>><\/span>\r\ndocument.getElementById(\"bg\").style.backgroundColor=\"#F00\";\r\n<\/span><\/<\/span>script<\/span>><\/span>\r\n<\/span><\/<\/span>head<\/span>><\/span>\r\n<\/span><<\/span>body<\/span>><\/span>\r\n <\/span><<\/span>div<\/span> <\/span>id<\/span>=<\/span>\"<\/span>bg<\/span>\"<\/span>><\/span><\/<\/span>div<\/span>><\/span>\r\n<\/span><\/<\/span>body<\/span>><\/span>\r\n<\/span><\/<\/span>html<\/span>><\/span><\/div><\/pre>\n

\u4ee5\u4e0a\u5b9e\u4f8b\u6211\u4eec\u8981\u5b9e\u73b0\u7684\u6548\u679c\u662f\u5c06 div \u7684\u80cc\u666f\u989c\u8272\u8bbe\u7f6e\u4e3a #F90\uff0c\u4f46\u662f\u5e76\u6ca1\u6709\u5b9e\u73b0\u6b64\u6548\u679c\uff0c\u56e0\u4e3a\u4ee3\u7801\u662f\u987a\u5e8f\u6267\u884c\u7684\uff0c\u5f53\u6267\u884c\u5230 document.getElementById(\"#bg\").style.backgroundColor=\"#F00\" \u7684\u65f6\u5019\uff0c\u8fd8\u6ca1\u6709\u52a0\u8f7d\u5230\u6b64 div \u5bf9\u8c61\uff0c\u6240\u4ee5\u80cc\u666f\u989c\u8272\u6ca1\u6709\u8bbe\u7f6e\u6210\u529f\u3002\u62a5\u9519\u4fe1\u606f\u5982\u4e0b\uff1a
\n\"\"<\/p>\n

\u6211\u4eec\u53ef\u4ee5\u6dfb\u52a0 window.onload \u5c31\u53ef\u4ee5\u6b63\u5e38\u6267\u884c\uff0c\u4ee3\u7801\u4fee\u6539\u5982\u4e0b:<\/p>\n

\u5b9e\u4f8b<\/strong><\/p>\n

<<\/span>!<\/span>DOCTYPE<\/span> <\/span>html<\/span>><\/span> \r\n<\/span><<\/span>html<\/span>><\/span> \r\n<\/span><<\/span>head<\/span>><\/span> \r\n<\/span><<\/span>meta<\/span> <\/span>charset<\/span>=<\/span>\"<\/span> utf-8<\/span>\"<\/span>><\/span> \r\n<\/span><<\/span>title<\/span>><\/span>\u4f7f\u7528 window.onload() \u6d4b\u8bd5<\/span><\/<\/span>title<\/span>><\/span>\r\n<\/span><<\/span>style<\/span> <\/span>type<\/span>=<\/span>\"<\/span>text\/css<\/span>\"<\/span>><\/span>\r\n#bg{\r\n width:120px;\r\n height:120px;\r\n border:4px solid blue;\r\n}\r\n<\/span><\/<\/span>style<\/span>><\/span>\r\n<\/span><<\/span>script<\/span> <\/span>type<\/span>=<\/span>\"<\/span>text\/javascript<\/span>\"<\/span>><\/span>\r\nwindow.onload=function(){\r\n document.getElementById(\"bg\").style.backgroundColor=\"#F00\";\r\n}\r\n<\/span><\/<\/span>script<\/span>><\/span>\r\n<\/span><\/<\/span>head<\/span>><\/span>\r\n<\/span><<\/span>body<\/span>><\/span>\r\n <\/span><<\/span>div<\/span> <\/span>id<\/span>=<\/span>\"<\/span>bg<\/span>\"<\/span>><\/span><\/<\/span>div<\/span>><\/span>\r\n<\/span><\/<\/span>body<\/span>><\/span>\r\n<\/span><\/<\/span>html<\/span>><\/span><\/div><\/pre>\n

window.onload \u4e8b\u4ef6\u7ed1\u5b9a\u4e8b\u4ef6\u5904\u7406\u51fd\u6570\uff0c\u7ed1\u5b9a\u7684\u662f\u4e00\u4e2a\u533f\u540d\u51fd\u6570\uff0c\u5f53\u7136\u4e5f\u53ef\u4ee5\u7ed1\u5b9a\u5177\u540d\u51fd\u6570\uff0c\u4ee3\u7801\u5b9e\u4f8b\u5982\u4e0b:<\/p>\n

\u5b9e\u4f8b<\/strong><\/p>\n

<<\/span>!<\/span>DOCTYPE<\/span> <\/span>html<\/span>><\/span> \r\n<\/span><<\/span>html<\/span>><\/span> \r\n<\/span><<\/span>head<\/span>><\/span> \r\n<\/span><<\/span>meta<\/span> <\/span>charset<\/span>=<\/span>\"<\/span> utf-8<\/span>\"<\/span>><\/span> \r\n<\/span><<\/span>title<\/span>><\/span>\u4f7f\u7528 window.onload() \u7ed1\u5b9a\u5177\u4f53\u51fd\u6570<\/span><\/<\/span>title<\/span>><\/span>\r\n<\/span><<\/span>script<\/span> <\/span>type<\/span>=<\/span>\"<\/span>text\/javascript<\/span>\"<\/span>><\/span>\r\n \r\n\/\/ \u51fd\u6570\u540d\u4e3a runoob\r\nwindow.onload=function runoob(){\r\n document.write(\"\u83dc\u9e1f\u6559\u7a0b -- \u5b66\u7684\u4e0d\u4ec5\u662f\u6280\u672f\uff0c\u66f4\u662f\u68a6\u60f3\uff01\uff01\uff01\");\r\n}\r\n<\/span><\/<\/span>script<\/span>><\/span>\r\n<\/span><\/<\/span>head<\/span>><\/span>\r\n<\/span><<\/span>body<\/span>><\/span>\r\n \r\n<\/span><\/<\/span>body<\/span>><\/span>\r\n<\/span><\/<\/span>html<\/span>><\/span><\/div><\/pre>\n

\u6709\u591a\u4e2a\u8981\u6267\u884c\u7684\u51fd\u6570\u5b9e\u4f8b\uff1a<\/p>\n

\u5b9e\u4f8b<\/strong><\/p>\n

<<\/span>!<\/span>DOCTYPE<\/span> <\/span>html<\/span>><\/span> \r\n<\/span><<\/span>html<\/span>><\/span> \r\n<\/span><<\/span>head<\/span>><\/span> \r\n<\/span><<\/span>meta<\/span> <\/span>charset<\/span>=<\/span>\"<\/span> utf-8<\/span>\"<\/span>><\/span> \r\n<\/span><<\/span>title<\/span>><\/span>\u4f7f\u7528 window.onload() \u6267\u884c\u591a\u4e2a\u51fd\u6570<\/span><\/<\/span>title<\/span>><\/span>\r\n<\/span><<\/span>style<\/span> <\/span>type<\/span>=<\/span>\"<\/span>text\/css<\/span>\"<\/span>><\/span>\r\n#bg{\r\n width:100px;\r\n height:100px;\r\n border:2px solid blue;\r\n}\r\n<\/span><\/<\/span>style<\/span>><\/span>\r\n<\/span><<\/span>script<\/span> <\/span>type<\/span>=<\/span>\"<\/span>text\/javascript<\/span>\"<\/span>><\/span>\r\nwindow.onload=function(){\r\n function runoob1(){\r\n document.getElementById(\"bg\").style.backgroundColor=\"#F00\";\r\n }\r\n function runoob2(){\r\n document.getElementById(\"bg\").style.width=\"200px\";\r\n document.getElementById(\"bg\").style.height=\"200px\";\r\n }\r\n runoob1();\r\n runoob2();\r\n}\r\n<\/span><\/<\/span>script<\/span>><\/span>\r\n<\/span><\/<\/span>head<\/span>><\/span>\r\n<\/span><<\/span>body<\/span>><\/span>\r\n <\/span><<\/span>div<\/span> <\/span>id<\/span>=<\/span>\"<\/span>bg<\/span>\"<\/span>><\/span><\/<\/span>div<\/span>><\/span>\r\n<\/span><\/<\/span>body<\/span>><\/span>\r\n<\/span><\/<\/span>html<\/span>><\/span><\/div><\/pre>\n
window.onload \u4e0e jQuery ready() \u533a\u522b<\/strong><\/div>\n
window.onload = function () {};    \/\/ JavaScript \r\n$(document).ready(function () {}); \/\/ jQuery<\/pre>\n

\u4ee5\u4e0a\u4e24\u79cd\u65b9\u5f0f\u90fd\u662f\u5728 HTML \u6587\u6863\u5b8c\u6bd5\u540e\u518d\u6267\u884c DOM \u64cd\u4f5c\uff0c\u4f46\u5b83\u4eec\u8fd8\u662f\u6709\u4e00\u5b9a\u7684\u533a\u522b\uff0c\u5982\u4e0b\u56fe\uff1a
\n\"\"<\/p>\n

<\/body><\/p>\n","protected":false},"excerpt":{"rendered":"

window.onload\uff08\uff09\u901a\u5e38\u7528\u4e8e\u5143\u7d20\uff0c\u5728\u9875\u9762\u5b8c\u5168\u52a0\u8f7d\u540e\uff08\u5305\u62ec\u56fe\u7247\uff0ccss\u6587\u4ef6\u7b49\u7b49\uff09\u6267\u884c\u811a\u672c\u4ee3\u7801\u3002 \u53ea\u6709\u4e00 […]<\/p>\n","protected":false},"author":321,"featured_media":211502,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-211487","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/211487","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/321"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=211487"}],"version-history":[{"count":19,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/211487\/revisions"}],"predecessor-version":[{"id":211841,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/211487\/revisions\/211841"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/211502"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=211487"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=211487"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=211487"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}