{"id":1044,"date":"2021-04-07T16:30:46","date_gmt":"2021-04-07T08:30:46","guid":{"rendered":"http:\/\/www.zyhcoding.club\/?p=1044"},"modified":"2021-04-12T20:45:07","modified_gmt":"2021-04-12T12:45:07","slug":"javascript-%e8%af%ad%e6%b3%95%e5%9f%ba%e7%a1%80","status":"publish","type":"post","link":"http:\/\/www.zyhcoding.club\/index.php\/2021\/04\/07\/javascript-%e8%af%ad%e6%b3%95%e5%9f%ba%e7%a1%80\/","title":{"rendered":"JavaScript \u8bed\u6cd5\u57fa\u7840"},"content":{"rendered":"<p>JavaScript \u662f\u4e00\u4e2a\u811a\u672c\u8bed\u8a00\u3002\u5b83\u662f\u4e00\u4e2a\u8f7b\u91cf\u7ea7\uff0c\u4f46\u529f\u80fd\u5f3a\u5927\u7684\u7f16\u7a0b\u8bed\u8a00\u3002JavaScript \u4f7f\u7528 Unicode \u5b57\u7b26\u96c6\u3002<br \/>\nJavaScript \u8bed\u53e5\u4f1a\u88ab\u6309\u7167\u4ee3\u7801\u7f16\u5199\u987a\u5e8f\u6267\u884c\u3002\u652f\u6301<code><code>\/\/<\/code>`<code>\u5355\u884c\u6ce8\u91ca\u548c<\/code>`<code>\/**\/<\/code><\/code>\u591a\u884c\u6ce8\u91ca\u3002<\/p>\n<hr \/>\n<h5>JavaScript \u6570\u636e\u7c7b\u578b\u548c\u53d8\u91cf<\/h5>\n<p>JavaScript \u5305\u542b\u5b57\u9762\u91cf\u548c\u53d8\u91cf\u3002\u53ef\u4ee5\u628a\u5b57\u9762\u91cf\u5f53\u6210\u5e38\u91cf\u6765\u7406\u89e3\u3002\u53d8\u91cf\u7528<code><code>var<\/code><\/code>\u5173\u952e\u5b57\u6765\u521b\u5efa\u3002JavaScript <strong>\u57fa\u672c\u6570\u636e\u7c7b\u578b<\/strong>\uff1a\u5b57\u7b26\u4e32(String)\u3001\u6570\u5b57(Number)\u3001\u5e03\u5c14(Boolean)\u3001\u5bf9\u7a7a(Null)\u3001\u672a\u5b9a\u4e49\u3001(Undefined)\u3001Symbol\u3002<strong>\u5f15\u7528\u6570\u636e\u7c7b\u578b<\/strong>\uff1a\u5bf9\u8c61(Object)\u3001\u6570\u7ec4(Array)\u3001\u51fd\u6570(Function)<\/p>\n<pre><code>var length = 16;                                  \/\/ Number \u901a\u8fc7\u6570\u5b57\u5b57\u9762\u91cf\u8d4b\u503c\nvar points = x * 10;                              \/\/ Number \u901a\u8fc7\u8868\u8fbe\u5f0f\u5b57\u9762\u91cf\u8d4b\u503c\nvar lastName = &quot;Johnson&quot;;                         \/\/ String \u901a\u8fc7\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u8d4b\u503c\nvar cars = [&quot;Saab&quot;, &quot;Volvo&quot;, &quot;BMW&quot;];              \/\/ Array  \u901a\u8fc7\u6570\u7ec4\u5b57\u9762\u91cf\u8d4b\u503c\nvar person = {firstName:&quot;John&quot;, lastName:&quot;Doe&quot;};  \/\/ Object \u901a\u8fc7\u5bf9\u8c61\u5b57\u9762\u91cf\u8d4b\u503c\n\nvar carname = new String;      \/\/ \u4f7f\u7528new\u5173\u952e\u5b57\u521b\u5efa\u5bf9\u8c61\u65f6\uff0c\u4f1a\u9ed8\u8ba4\u8d4b\u503c\nvar x =       new Number;      \/\/ x = 0\nvar y =       new Boolean;     \/\/ y = false\nvar cars =    new Array;       \/\/\nvar person =  new Object;      \/\/ [object Object]\n<\/code><\/pre>\n<p>\u53ef\u7528<code><code>const<\/code><\/code>\u5173\u952e\u5b57\u58f0\u660e\u5e76\u521d\u59cb\u5316\u4e00\u4e2a\u5e38\u91cf\uff0c\u4e0d\u5141\u8bb8\u6539\u53d8\u503c\u3002<br \/>\n\u5f53\u518d\u6b21\u58f0\u660e\u4e00\u4e2a\u5df2\u7ecf\u58f0\u660e\u8fc7\u7684\u53d8\u91cf\u65f6\uff0c\u82e5\u6ca1\u6709\u8d4b\u65b0\u7684\u503c\u5219\u8be5\u53d8\u91cf\u4ecd\u4fdd\u6709\u539f\u6765\u7684\u503c\uff0c\u4e0d\u4f1a\u62a5\u9519\u3002<br \/>\n\u5728 JavaScript \u51fd\u6570\u5185\u90e8\u58f0\u660e\u7684\u53d8\u91cf\uff08\u4f7f\u7528 var\uff09\u662f\u5c40\u90e8\u53d8\u91cf\uff0c\u6240\u4ee5\u53ea\u80fd\u5728\u51fd\u6570\u5185\u90e8\u8bbf\u95ee\u5b83\u3002\u5728\u51fd\u6570\u5916\u58f0\u660e\u7684\u53d8\u91cf\u662f\u5168\u5c40\u53d8\u91cf\uff0c\u7f51\u9875\u4e0a\u7684\u6240\u6709\u811a\u672c\u548c\u51fd\u6570\u90fd\u80fd\u8bbf\u95ee\u5b83\u3002<br \/>\n\u5f53\u628a\u503c\u8d4b\u7ed9\u4e00\u4e2a\u5c1a\u672a\u58f0\u660e\u7684\u53d8\u91cf\u65f6\uff0c\u8be5\u53d8\u91cf\u5c06\u88ab\u81ea\u52a8\u4f5c\u4e3a<code><code>window<\/code>`<code>\u7684\u4e00\u4e2a\u5c5e\u6027\uff0c\u53ef\u7528<\/code>`<code>window.varname<\/code>`<code>\u6765\u8bbf\u95ee\uff0c\u5e76\u4e14\u53ef\u4ee5\u901a\u8fc7<\/code>`<code>delete<\/code><\/code>\u8bed\u53e5\u5220\u9664\u53d8\u91cf\u3002<\/p>\n<h5>JavaScript \u51fd\u6570\u8bed\u6cd5<\/h5>\n<p>\u4f7f\u7528\u5173\u952e\u5b57<code><code>function<\/code><\/code>\u6765\u5b9a\u4e49\u51fd\u6570\uff1a<\/p>\n<pre><code>function FunctionName (argument1, argument2) {\n    ;\n    return;\n}<\/code><\/pre>\n<p>\u51fd\u6570\u7684\u53c2\u6570\u4e0d\u9700\u8981\u7c7b\u578b\uff0c\u56e0\u4e3a\u90fd\u662f\u7528<code><code>var<\/code>`<code>\u7533\u8bf7\u7684\uff0c\u4f46\u4f7f\u7528\u65f6\u8981\u4fdd\u8bc1\u7c7b\u578b\u4e00\u81f4\u3002<\/code>`<code>return<\/code><\/code>\u8bed\u53e5\u53ef\u6709\u53ef\u65e0\uff0c\u6267\u884c\u8be5\u8bed\u53e5\u65f6\u51fd\u6570\u505c\u6b62\u6267\u884c\uff0c\u5e76\u8fd4\u56de\u503c\u3002<\/p>\n<h5>JavaScript \u8f93\u51fa<\/h5>\n<p>\u6709\u591a\u79cd\u8f93\u51fa\u65b9\u5f0f\uff1a<\/p>\n<pre><code>alert(&quot;&quot;);  \/\/\u5f39\u51fa\u8b66\u544a\u6846\ndocument.write(&quot;&quot;);   \/\/\u8be5\u65b9\u6cd5\u5c06\u5185\u5bb9\u5199\u5165HTML\u6587\u6863\u4e2d\u3002\u5728\u6240\u4ee5\u6587\u6863\u90fd\u52a0\u8f7d\u5b8c\u6bd5\u540e\u518d\u4f7f\u7528\u8be5\u8bed\u53e5\u65f6\uff0c\u8986\u76d6\u539f\u6587\u6863\uff0c\u91cd\u65b0\u5f00\u59cb\u5199\u3002\ndocument.getElementById(&quot;demo&quot;).innerHTML=&quot;hello zyh!&quot;;   \/\/innerHTML\u65b9\u6cd5\u4f1a\u6539\u53d8\u8fd9\u4e2aid\u7684\u5185\u5bb9\u3002\nconsole.log(&quot;&quot;)\uff1b    \/\/\u8be5\u65b9\u6cd5\u4f1a\u628a\u5185\u5bb9\u5199\u5165\u5230\u6d4f\u89c8\u5668\u7684\u63a7\u5236\u53f0<\/code><\/pre>\n<h5>JavaScript \u5bf9\u8c61<\/h5>\n<p>\u5728 JavaScript\u4e2d\uff0c\u51e0\u4e4e\u6240\u6709\u7684\u4e8b\u7269\u90fd\u662f\u5bf9\u8c61\u3002\u5bf9\u8c61\u4e5f\u662f\u53d8\u91cf\uff0c\u4f46\u5bf9\u8c61\u53ef\u4ee5\u5305\u542b\u591a\u4e2a\u53d8\u91cf\uff0c\u6bcf\u4e2a\u53d8\u91cf\u4ee5<code><code>name:value<\/code><\/code>\u7684\u5f62\u5f0f\u51fa\u73b0\u3002<\/p>\n<pre><code>var  handsomeguy= {name:&quot;zyh&quot;,\n        sex:&quot;male&quot;,\n        facescore:&quot;+\u221e&quot;,\n        fullname : function () {\n            return &quot;\u5f20\u715c\u6657&quot;;\n        }\n    };<\/code><\/pre>\n<p>\u5bf9\u8c61\u7684\u53d8\u91cf\u548c\u65b9\u6cd5\u53ef\u4ee5\u901a\u8fc7<code><code>.<\/code>`<code>\u6765\u8bbf\u95ee\u6216\u8005\u8c03\u7528\u3002\u53d8\u91cf\u4e5f\u53ef\u4ee5\u901a\u8fc7<\/code>`<code>handsomeguy[&quot;sex&quot;]<\/code><\/code>\u8fd9\u79cd\u65b9\u6cd5\u6765\u8bbf\u95ee\u3002<br \/>\n\u51fd\u6570\u4e5f\u53ef\u4ee5\u4f5c\u4e3a\u5bf9\u8c61\u7684\u4e00\u4e2a\u5c5e\u6027\u800c\u4e0d\u662f\u65b9\u6cd5\uff1a\u5f53\u8c03\u7528\u65f6\u4e0d\u5e26<code><code>()<\/code><\/code>\u4f1a\u8fd4\u56de\u51fd\u6570\u7684\u5b9a\u4e49\u3002<\/p>\n<h5>JavaScript \u6570\u7ec4<\/h5>\n<p>Array. \u6570\u7ec4\u53d8\u91cf\u53ef\u4ee5\u7528new\u5173\u952e\u5b57\u6765\u521b\u5efa\uff0c\u4e5f\u53ef\u4ee5\u5728\u521b\u5efa\u53d8\u91cf\u65f6\u521d\u59cb\u5316<\/p>\n<pre><code>var arr = {&quot;hello&quot;, &quot;world&quot;, &quot;love you!&quot;};\nvar arr = new Array();\narr[100] = &quot;zyh&quot;;             \/\/ arr\u7684length\u4ece0\u53d8\u4e3a101<\/code><\/pre>\n<p>\u4f7f\u7528\u6570\u7ec4\u65f6\u53ef\u4ee5\u76f4\u63a5\u8bbf\u95ee\u4efb\u610f\u4e0b\u6807\uff0c\u4e0d\u7528\u63d0\u524d\u5b9a\u4e49\uff0c\u6570\u7ec4\u5b9e\u9645\u5927\u5c0f\u4e3a\u6700\u5927\u4e0b\u6807\u8bbf\u95ee\u503c\u3002<\/p>\n<h5>HTML \u4e2d\u7684\u6807\u7b7e\u5728JavaScript\u4e2d\u88ab\u8c03\u7528<\/h5>\n<pre><code>x = document.forms[&quot;myform&quot;][&quot;apple&quot;].ischecked;    \/\/ \u8fd4\u56deapple\u662f\u5426\u88ab\u9009\u4e2d(true:false);\nx = document.getElementById(&quot;in&quot;).value.split(&#039; &#039;); \/\/ id\u4e3ain\u7684\u8f93\u5165\u6846\u7684\u503c\u88absplit\u5185\u7684\u5b57\u4e32\u5206\u5272\u540e\uff0c\u8fd4\u56de\u6570\u7ec4\u7ed9x<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>JavaScript \u662f\u4e00\u4e2a\u811a\u672c\u8bed\u8a00\u3002\u5b83\u662f\u4e00\u4e2a\u8f7b\u91cf\u7ea7\uff0c\u4f46\u529f\u80fd\u5f3a\u5927\u7684\u7f16\u7a0b\u8bed\u8a00\u3002JavaScript \u4f7f [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[69],"tags":[],"_links":{"self":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts\/1044"}],"collection":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/comments?post=1044"}],"version-history":[{"count":17,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts\/1044\/revisions"}],"predecessor-version":[{"id":1065,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts\/1044\/revisions\/1065"}],"wp:attachment":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/media?parent=1044"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/categories?post=1044"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/tags?post=1044"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}