{"id":173020,"date":"2020-03-31T09:00:20","date_gmt":"2020-03-31T01:00:20","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=173020"},"modified":"2020-03-19T16:38:05","modified_gmt":"2020-03-19T08:38:05","slug":"introduction-to-javascript-3","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/introduction-to-javascript-3.html","title":{"rendered":"JavaScript \u8f93\u51fa\u4ecb\u7ecd"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nJavaScript \u662f\u4e92\u8054\u7f51\u4e0a\u6700\u6d41\u884c\u7684\u811a\u672c\u8bed\u8a00\uff0c\u8fd9\u95e8\u8bed\u8a00\u53ef\u7528\u4e8e HTML \u548c web\uff0c\u66f4\u53ef\u5e7f\u6cdb\u7528\u4e8e\u670d\u52a1\u5668\u3001PC\u3001\u7b14\u8bb0\u672c\u7535\u8111\u3001\u5e73\u677f\u7535\u8111\u548c\u667a\u80fd\u624b\u673a\u7b49\u8bbe\u5907\u3002JavaScript \u6ca1\u6709\u4efb\u4f55\u6253\u5370\u6216\u8005\u8f93\u51fa\u7684\u51fd\u6570\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/p>\n

JavaScript \u663e\u793a\u6570\u636e<\/strong><\/div>\n

JavaScript \u53ef\u4ee5\u901a\u8fc7\u4e0d\u540c\u7684\u65b9\u5f0f\u6765\u8f93\u51fa\u6570\u636e\uff1a<\/p>\n

    \n
  • \u4f7f\u7528 window.alert()<\/strong> \u5f39\u51fa\u8b66\u544a\u6846\u3002<\/li>\n
  • \u4f7f\u7528 document.write()<\/strong> \u65b9\u6cd5\u5c06\u5185\u5bb9\u5199\u5230 HTML \u6587\u6863\u4e2d\u3002<\/li>\n
  • \u4f7f\u7528 innerHTML<\/strong> \u5199\u5165\u5230 HTML \u5143\u7d20\u3002<\/li>\n
  • \u4f7f\u7528 console.log()<\/strong> \u5199\u5165\u5230\u6d4f\u89c8\u5668\u7684\u63a7\u5236\u53f0\u3002<\/li>\n<\/ul>\n
    \u4f7f\u7528 window.alert()<\/strong><\/div>\n

    \u4f60\u53ef\u4ee5\u5f39\u51fa\u8b66\u544a\u6846\u6765\u663e\u793a\u6570\u636e\uff1a<\/p>\n

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

    <<\/span>!DOCTYPE<\/span> html<\/span>>\r\n<<\/span>html<\/span>>\r\n<<\/span>body<\/span>>\r\n<<\/span>h1<\/span>><\/span>\u6211\u7684\u7b2c\u4e00\u4e2a\u9875\u9762<<\/span>\/h1<\/span>><\/span>
    <<\/span>p<\/span>><\/span>\u6211\u7684\u7b2c\u4e00\u4e2a\u6bb5\u843d\u3002<<\/span>\/p<\/span>>\r\n<<\/span>script<\/span>><\/span>
    window.alert(5 + 6);\r\n<<\/span>\/script<\/span>>\r\n<<\/span>\/body<\/span>>\r\n<<\/span>\/html<\/span>><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/pre>\n
    \u64cd\u4f5c HTML \u5143\u7d20<\/strong><\/div>\n

    \u5982\u9700\u4ece JavaScript \u8bbf\u95ee\u67d0\u4e2a HTML \u5143\u7d20\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 document.getElementById(id) \u65b9\u6cd5\u3002<\/p>\n

    \u8bf7\u4f7f\u7528 \"id\" \u5c5e\u6027\u6765\u6807\u8bc6 HTML \u5143\u7d20\uff0c\u5e76 innerHTML \u6765\u83b7\u53d6\u6216\u63d2\u5165\u5143\u7d20\u5185\u5bb9\uff1a<\/p>\n

    \u5b9e\u4f8b<\/p>\n

    <<\/span>!DOCTYPE<\/span> html<\/span>><\/span>
    <<\/span>html<\/span>>\r\n<<\/span>body<\/span>>\r\n<<\/span>h1<\/span>><\/span>\u6211\u7684\u7b2c\u4e00\u4e2a Web \u9875\u9762<<\/span>\/h1<\/span>>\r\n<<\/span>p<\/span> id=<\/span>\"demo\"<\/span>><\/span>\u6211\u7684\u7b2c\u4e00\u4e2a\u6bb5\u843d<<\/span>\/p<\/span>>\r\n<<\/span>script<\/span>><\/span>
    \r\n\tdocument.getElementById(\"demo\").innerHTML = \"\u6bb5\u843d\u5df2\u4fee\u6539\u3002\";
    \r\n<<\/span>\/script<\/span>>\r\n<<\/span>\/body<\/span>>\r\n<<\/span>\/html<\/span>><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/pre>\n

    \u4ee5\u4e0a JavaScript \u8bed\u53e5\uff08\u5728 <script> \u6807\u7b7e\u4e2d\uff09\u53ef\u4ee5\u5728 web \u6d4f\u89c8\u5668\u4e2d\u6267\u884c\uff1a<\/p>\n

    document.getElementById(\"demo\")<\/strong> \u662f\u4f7f\u7528 id \u5c5e\u6027\u6765\u67e5\u627e HTML \u5143\u7d20\u7684 JavaScript \u4ee3\u7801 \u3002<\/p>\n

    innerHTML = \"\u6bb5\u843d\u5df2\u4fee\u6539\u3002\"<\/strong> \u662f\u7528\u4e8e\u4fee\u6539\u5143\u7d20\u7684 HTML \u5185\u5bb9(innerHTML)\u7684JavaScript \u4ee3\u7801\u3002 <\/p>\n

    \u5728\u672c\u6559\u7a0b\u4e2d<\/strong><\/div>\n

    \u5728\u5927\u591a\u6570\u60c5\u51b5\u4e0b\uff0c\u5728\u672c\u6559\u7a0b\u4e2d\uff0c\u6211\u4eec\u5c06\u4f7f\u7528\u4e0a\u9762\u63cf\u8ff0\u7684\u65b9\u6cd5\u6765\u8f93\u51fa\uff1a<\/p>\n

    \u4e0a\u9762\u7684\u4f8b\u5b50\u76f4\u63a5\u628a id=\"demo\" \u7684 <p> \u5143\u7d20\u5199\u5230 HTML \u6587\u6863\u8f93\u51fa\u4e2d\uff1a<\/p>\n

    \u5199\u5230 HTML \u6587\u6863<\/strong><\/div>\n

    \u51fa\u4e8e\u6d4b\u8bd5\u76ee\u7684\uff0c\u60a8\u53ef\u4ee5\u5c06JavaScript\u76f4\u63a5\u5199\u5728HTML \u6587\u6863\u4e2d\uff1a<\/p>\n

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

    <<\/span>!DOCTYPE<\/span> html<\/span>><\/span>
    <<\/span>html<\/span>>\r\n<<\/span>body<\/span>><\/span>

    <<\/span>h1<\/span>><\/span>\u6211\u7684\u7b2c\u4e00\u4e2a Web \u9875\u9762<<\/span>\/h1<\/span>>\r\n\t
    <<\/span>p<\/span>><\/span>\u6211\u7684\u7b2c\u4e00\u4e2a\u6bb5\u843d\u3002<<\/span>\/p<\/span>>\r\n\t
    <<\/span>script<\/span>><\/span>
    document.write(Date());
    \r\n<<\/span>\/script<\/span>>\r\n<<\/span>\/body<\/span>>\r\n<<\/span>\/html<\/span>><\/span><\/span><\/span><\/span><\/span><\/span><\/pre>\n

    \u8bf7\u4f7f\u7528 document.write() \u4ec5\u4ec5\u5411\u6587\u6863\u8f93\u51fa\u5199\u5185\u5bb9\u3002<\/p>\n

    \u5982\u679c\u5728\u6587\u6863\u5df2\u5b8c\u6210\u52a0\u8f7d\u540e\u6267\u884c document.write\uff0c\u6574\u4e2a HTML \u9875\u9762\u5c06\u88ab\u8986\u76d6\u3002
    \n\u5b9e\u4f8b<\/strong><\/p>\n

    <<\/span>!DOCTYPE<\/span> html<\/span>>\r\n<<\/span>html<\/span>>\r\n<<\/span>body<\/span>>\r\n<<\/span>h1<\/span>><\/span>\u6211\u7684\u7b2c\u4e00\u4e2a Web \u9875\u9762<<\/span>\/h1<\/span>>\r\n
    <<\/span>p<\/span>><\/span>\u6211\u7684\u7b2c\u4e00\u4e2a\u6bb5\u843d\u3002<<\/span>\/p<\/span>>\r\n<<\/span>button<\/span> onclick=<\/span>\"myFunction()\"<\/span>><\/span>\u70b9\u6211<<\/span>\/button<\/span>>\r\n<<\/span>script<\/span>>\r\nfunction myFunction() {
    \r\n   \tdocument.write(Date());
    \r\n}
    \r\n<<\/span>\/script<\/span>>\r\n<<\/span>\/body<\/span>>\r\n<<\/span>\/html<\/span>><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/pre>\n
    \u5199\u5230\u63a7\u5236\u53f0<\/strong><\/div>\n

    \u5982\u679c\u60a8\u7684\u6d4f\u89c8\u5668\u652f\u6301\u8c03\u8bd5\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528 console.log() \u65b9\u6cd5\u5728\u6d4f\u89c8\u5668\u4e2d\u663e\u793a JavaScript \u503c\u3002<\/p>\n

    \u6d4f\u89c8\u5668\u4e2d\u4f7f\u7528 F12 \u6765\u542f\u7528\u8c03\u8bd5\u6a21\u5f0f\uff0c \u5728\u8c03\u8bd5\u7a97\u53e3\u4e2d\u70b9\u51fb \"Console\" \u83dc\u5355\u3002<\/p>\n

    \r\n<<\/span>!DOCTYPE<\/span> html<\/span>>\r\n<<\/span>html<\/span>>\r\n<<\/span>body<\/span>>\r\n<<\/span>h1<\/span>><\/span>\u6211\u7684\u7b2c\u4e00\u4e2a Web \u9875\u9762<<\/span>\/h1<\/span>>\r\n<<\/span>script<\/span>>\r\na = 5;
    \r\nb = 6;
    \r\nc = a + b;
    \r\nconsole.log(c);
    \r\n<<\/span>\/script<\/span>>\r\n<<\/span>\/body<\/span>>\r\n<<\/span>\/html<\/span>><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/pre>\n

    \u5b9e\u4f8b console \u622a\u56fe\uff1a<\/strong>
    \n\"\"<\/p>\n

    \u60a8\u77e5\u9053\u5417?<\/strong><\/div>\n

    \u7a0b\u5e8f\u4e2d\u8c03\u8bd5\u662f\u6d4b\u8bd5\uff0c\u67e5\u627e\u53ca\u51cf\u5c11bug(\u9519\u8bef)\u7684\u8fc7\u7a0b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

    JavaScript \u53ef\u4ee5\u901a\u8fc7\u4e0d\u540c\u7684\u65b9\u5f0f\u6765\u8f93\u51fa\u6570\u636e\uff1a \u4f7f\u7528 window.alert() \u5f39\u51fa\u8b66\u544a\u6846\u3002 \u4f7f\u7528 […]<\/p>\n","protected":false},"author":321,"featured_media":173045,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-173020","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\/173020","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=173020"}],"version-history":[{"count":17,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/173020\/revisions"}],"predecessor-version":[{"id":173431,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/173020\/revisions\/173431"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/173045"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=173020"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=173020"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=173020"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}