{"id":10,"date":"2007-05-20T23:52:48","date_gmt":"2007-05-21T03:52:48","guid":{"rendered":"http:\/\/prglab.com\/blog\/?page_id=10"},"modified":"2010-07-19T15:05:44","modified_gmt":"2010-07-19T19:05:44","slug":"js-variables","status":"publish","type":"page","link":"https:\/\/www.prglab.com\/blog\/js-tutorial\/js-variables","title":{"rendered":"JavaScript\u4e2d\u7684\u53d8\u91cf"},"content":{"rendered":"<p>\u53d8\u91cf\u662f\u5b58\u50a8\u4fe1\u606f\u7684\u201c\u5bb9\u5668\u201d\u3002<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\n<strong>\u53d8\u91cf<\/strong><\/p>\n<p>\u53d8\u91cf\u662f\u4e00\u4e2a\u201c\u5bb9\u5668\u201d\uff0c\u7528\u6765\u88c5\u4f60\u8981\u5b58\u50a8\u7684\u4fe1\u606f\u3002\u4e00\u4e2a\u53d8\u91cf\u7684\u503c\u53ef\u4ee5\u5728\u811a\u672c\u4e2d\u88ab\u6539\u53d8\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u540d\u79f0\u6765\u5f15\u7528\u4e00\u4e2a\u53d8\u91cf\uff0c\u5bdf\u770b\u6216\u6539\u53d8\u5b83\u7684\u503c\u3002<\/p>\n<p>JavaScript\u4e2d\u53d8\u91cf\u547d\u540d\u7684\u89c4\u5219\uff1a<\/p>\n<ul>\n<li>\u53d8\u91cf\u540d\u79f0\u533a\u5206\u5927\u5c0f\u5199<\/li>\n<li>\u53d8\u91cf\u540d\u5fc5\u987b\u4ee5\u5b57\u6bcd\u6216\u4e0b\u753b\u7ebf\u5f00\u5934<\/li>\n<\/ul>\n<p><strong>\u91cd\u70b9!<\/strong> JavaScript \u662f\u533a\u5206\u5927\u5c0f\u5199\u7684\uff01\u53d8\u91cf\u540dstrname \u548cSTRNAME\u6307\u7684\u662f\u4e0d\u540c\u7684\u53d8\u91cf\uff01<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\n<strong>\u53d8\u91cf\u7684\u58f0\u660e\u548c\u8d4b\u503c<\/strong><\/p>\n<p>\u5728JavaScript\u4e2d\uff0c\u53d8\u91cf\u58f0\u660e\u662f\u4f7f\u7528\u5173\u952e\u5b57 var \u6765\u5b8c\u6210\u7684\uff0c\u4f8b\u5982\uff1a<\/p>\n<p>var myUrl = &#8220;http:\/\/www.prglab.com&#8221;<\/p>\n<p>\u8fd9\u4e0e\u5176\u4ed6\u7f16\u7a0b\u8bed\u8a00\u5b9a\u4e49\u4e0d\u540c\u7c7b\u578b\u7684\u53d8\u91cf\u4f7f\u7528int, string, double, boolean\u7b49\u4e0d\u540c\u7684\u5173\u952e\u5b57\u6709\u6240\u4e0d\u540c\uff0c\u53ef\u4ee5\u8bf4\u7b80\u5316\u5f88\u591a\u3002<\/p>\n<p>\u53e6\u5916\u5728JavaScript\u4e2d\uff0c\u53d8\u91cf\u4e5f\u53ef\u4ee5\u4e0d\u7ecf\u58f0\u660e\u800c\u76f4\u63a5\u4f7f\u7528\uff0c\u6216\u8005\u8bf4\u5728\u7b2c\u4e00\u6b21\u4f7f\u7528\u7684\u540c\u65f6\u81ea\u52a8\u58f0\u660e\uff0c\u4f8b\u5982\u76f4\u63a5\u5199\uff1a<\/p>\n<p>myUrl = &#8220;http:\/\/www.prglab.com&#8221;<\/p>\n<p>\u5982\u679cmyUrl\u53d8\u91cf\u5728\u524d\u9762\u6ca1\u6709\u88abvar\u58f0\u660e\u8fc7\uff0c\u5219\u5728\u6b64\u7b2c\u4e00\u6b21\u4f7f\u7528\u65f6\u4f1a\u81ea\u52a8\u751f\u6210\u53d8\u91cf\u3002\u8fd9\u6837\u4f3c\u4e4eJavaScript\u4e2d\u5b9a\u4e49\u53d8\u91cf\u662f\u5426\u4f7f\u7528\u5173\u952e\u5b57var\u6ca1\u6709\u592a\u5927\u533a\u522b\u3002\u5bf9\u5168\u5c40\u53d8\u91cf\u6765\u8bf4\uff0c\u662f\u5426\u4f7f\u7528var\u505a\u58f0\u660e\u7684\u786e\u662f\u6ca1\u6709\u4ec0\u4e48\u533a\u522b\u7684\uff0c\u4e5f\u5c31\u662f\u8bf4\u5982\u679c\u4f60\u5728\u6240\u6709\u51fd\u6570\u4e4b\u5916\u5b9a\u4e49\u4e00\u4e2a\u53d8\u91cf\uff0c\u662f\u5426\u4f7f\u7528var\u662f\u6ca1\u6709\u533a\u522b\u7684\u3002<\/p>\n<p>\u4f46\u5bf9\u5c40\u90e8\u53d8\u91cf(\u5728\u51fd\u6570function\u4e2d\u5b9a\u4e49\u7684\u53d8\u91cf)\u8fd8\u662f\u6709\u4e9b\u533a\u522b\u7684\u3002\u5728\u51fd\u6570\u4e2d\u5b9a\u4e49\u53d8\u91cf\u5982\u679c\u4e0d\u4f7f\u7528\u5173\u952e\u5b57var\uff0c\u5219\u53d8\u91cf\u4f1a\u88ab\u5b9a\u4e49\u4e3a\u5168\u5c40\u53d8\u91cf\u3002\u7279\u522b\u8981\u6ce8\u610f\u7684\u662f\u5982\u679c\u4f60\u8981\u5b9a\u4e49\u7684\u5c40\u90e8\u53d8\u91cf\u5df2\u7ecf\u6709\u540c\u540d\u7684\u5168\u5c40\u53d8\u91cf\uff0c\u90a3\u4e48\u4f7f\u7528var\u4f1a\u751f\u6210\u4e00\u4e2a\u65b0\u7684\u5c40\u90e8\u53d8\u91cf\uff0c\u4ece\u800c\u907f\u514d\u4e0d\u5c0f\u5fc3\u4fee\u6539\u4e86\u5168\u5c40\u53d8\u91cf\u7684\u503c\u3002<\/p>\n<p>\u6240\u4ee5\u6700\u597d\u7684\u4e60\u60ef\u505a\u6cd5\u662f\uff1a \u603b\u4f7f\u7528var\u6765\u5b9a\u4e49\u58f0\u660e\u4e00\u4e2a\u53d8\u91cf\u3002<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\n<strong>\u53d8\u91cf\u7684\u6709\u6548\u671f<\/strong><\/p>\n<p>\u5728\u51fd\u6570\u4e2d\u5b9a\u4e49\u7684\u53d8\u91cf\u53ea\u80fd\u591f\u5728\u8be5\u51fd\u6570\u4e2d\u8bbf\u95ee\u3002\u5f53\u9000\u51fa\u8be5\u51fd\u6570\u65f6\uff0c\u53d8\u91cf\u5c31\u88ab\u9500\u6bc1\u4e86\u3002\u8fd9\u4e9b\u53d8\u91cf\u53eb\u505a\u672c\u5730\u53d8\u91cf\u3002\u4e0d\u540c\u51fd\u6570\u4e2d\u7684\u672c\u5730\u53d8\u91cf\u53ef\u4ee5\u540c\u540d\uff0c\u56e0\u4e3a\u6bcf\u4e00\u4e2a\u672c\u5730\u53d8\u91cf\u90fd\u53ea\u662f\u5728\u5b9a\u4e49\u5b83\u7684\u51fd\u6570\u4e2d\u6709\u6548\u3002<\/p>\n<p>\u5982\u679c\u5728\u51fd\u6570\u5916\u9762\u5b9a\u4e49\u4e00\u4e2a\u53d8\u91cf\uff0c\u90a3\u4e48\u8be5\u9875\u9762\u4e0a\u7684\u6240\u6709\u51fd\u6570\u90fd\u53ef\u4ee5\u8bbf\u95ee\u8fd9\u4e2a\u53d8\u91cf\u3002\u8fd9\u4e2a\u53d8\u91cf\u7684\u6709\u6548\u671f\u4ece\u5b83\u88ab\u5b9a\u4e49\u5f00\u59cb\uff0c\u5230\u8be5\u9875\u9762\u88ab\u5173\u95ed\u4e3a\u6b62\u3002<\/p>\n<p><strong>\u6ce8\u610f\uff1a<\/strong>\u5728JavaScript\u4e2d\u53d8\u91cf\u662f\u53ef\u4ee5\u88ab\u91cd\u590d\u58f0\u660e\u7684\uff0c\u5e76\u4e14\u5f53\u53d8\u91cf\u88ab\u91cd\u590d\u58f0\u660e\u65f6\u5e76\u4e0d\u4f1a\u5931\u53bb\u5176\u539f\u5148\u7684\u503c\uff0c\u4f8b\u5982\uff1a<\/p>\n<p>[javascript]<br \/>\nvar myUrl = &#8220;http:\/\/www.prglab.com&#8221;<br \/>\nvar myUrl<br \/>\n[\/javascript]<\/p>\n<p>\u8fd9\u4e24\u884c\u4ee3\u7801\u6267\u884c\u540e\uff0cmyUrl\u7136\u662fhttp:\/\/www.prglab.com\uff0c\u800c\u4e0d\u4f1a\u88ab\u7f6e\u7a7a\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u53d8\u91cf\u662f\u5b58\u50a8\u4fe1\u606f\u7684\u201c\u5bb9\u5668\u201d\u3002 &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; \u53d8\u91cf \u53d8\u91cf\u662f\u4e00\u4e2a\u201c\u5bb9\u5668\u201d\uff0c\u7528\u6765\u88c5\u4f60\u8981\u5b58\u50a8\u7684\u4fe1\u606f\u3002\u4e00\u4e2a\u53d8\u91cf\u7684\u503c\u53ef\u4ee5\u5728\u811a\u672c\u4e2d\u88ab\u6539\u53d8\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u540d\u79f0\u6765\u5f15\u7528\u4e00\u4e2a\u53d8\u91cf\uff0c\u5bdf\u770b\u6216\u6539\u53d8\u5b83\u7684\u503c\u3002 JavaScript\u4e2d\u53d8\u91cf\u547d\u540d\u7684\u89c4\u5219\uff1a \u53d8\u91cf\u540d\u79f0\u533a\u5206\u5927\u5c0f\u5199 \u53d8\u91cf\u540d\u5fc5\u987b\u4ee5\u5b57\u6bcd\u6216\u4e0b\u753b\u7ebf\u5f00\u5934 \u91cd\u70b9! JavaScript \u662f\u533a\u5206\u5927\u5c0f\u5199\u7684\uff01\u53d8\u91cf\u540dstrname \u548cSTRNAME\u6307\u7684\u662f\u4e0d\u540c\u7684\u53d8\u91cf\uff01 &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; \u53d8\u91cf\u7684\u58f0\u660e\u548c\u8d4b\u503c \u5728JavaScript\u4e2d\uff0c\u53d8\u91cf\u58f0\u660e\u662f\u4f7f\u7528\u5173\u952e\u5b57 var \u6765\u5b8c\u6210\u7684\uff0c\u4f8b\u5982\uff1a var myUrl = &#8220;http:\/\/www.prglab.com&#8221; \u8fd9\u4e0e\u5176\u4ed6\u7f16\u7a0b\u8bed\u8a00\u5b9a\u4e49\u4e0d\u540c\u7c7b\u578b\u7684\u53d8\u91cf\u4f7f\u7528int, string, double, boolean\u7b49\u4e0d\u540c\u7684\u5173\u952e\u5b57\u6709\u6240\u4e0d\u540c\uff0c\u53ef\u4ee5\u8bf4\u7b80\u5316\u5f88\u591a\u3002 \u53e6\u5916\u5728JavaScript\u4e2d\uff0c\u53d8\u91cf\u4e5f\u53ef\u4ee5\u4e0d\u7ecf\u58f0\u660e\u800c\u76f4\u63a5\u4f7f\u7528\uff0c\u6216\u8005\u8bf4\u5728\u7b2c\u4e00\u6b21\u4f7f\u7528\u7684\u540c\u65f6\u81ea\u52a8\u58f0\u660e\uff0c\u4f8b\u5982\u76f4\u63a5\u5199\uff1a myUrl = &#8220;http:\/\/www.prglab.com&#8221; \u5982\u679cmyUrl\u53d8\u91cf\u5728\u524d\u9762\u6ca1\u6709\u88abvar\u58f0\u660e\u8fc7\uff0c\u5219\u5728\u6b64\u7b2c\u4e00\u6b21\u4f7f\u7528\u65f6\u4f1a\u81ea\u52a8\u751f\u6210\u53d8\u91cf\u3002\u8fd9\u6837\u4f3c\u4e4eJavaScript\u4e2d\u5b9a\u4e49\u53d8\u91cf\u662f\u5426\u4f7f\u7528\u5173\u952e\u5b57var\u6ca1\u6709\u592a\u5927\u533a\u522b\u3002\u5bf9\u5168\u5c40\u53d8\u91cf\u6765\u8bf4\uff0c\u662f\u5426\u4f7f\u7528var\u505a\u58f0\u660e\u7684\u786e\u662f\u6ca1\u6709\u4ec0\u4e48\u533a\u522b\u7684\uff0c\u4e5f\u5c31\u662f\u8bf4\u5982\u679c\u4f60\u5728\u6240\u6709\u51fd\u6570\u4e4b\u5916\u5b9a\u4e49\u4e00\u4e2a\u53d8\u91cf\uff0c\u662f\u5426\u4f7f\u7528var\u662f\u6ca1\u6709\u533a\u522b\u7684\u3002 \u4f46\u5bf9\u5c40\u90e8\u53d8\u91cf(\u5728\u51fd\u6570function\u4e2d\u5b9a\u4e49\u7684\u53d8\u91cf)\u8fd8\u662f\u6709\u4e9b\u533a\u522b\u7684\u3002\u5728\u51fd\u6570\u4e2d\u5b9a\u4e49\u53d8\u91cf\u5982\u679c\u4e0d\u4f7f\u7528\u5173\u952e\u5b57var\uff0c\u5219\u53d8\u91cf\u4f1a\u88ab\u5b9a\u4e49\u4e3a\u5168\u5c40\u53d8\u91cf\u3002\u7279\u522b\u8981\u6ce8\u610f\u7684\u662f\u5982\u679c\u4f60\u8981\u5b9a\u4e49\u7684\u5c40\u90e8\u53d8\u91cf\u5df2\u7ecf\u6709\u540c\u540d\u7684\u5168\u5c40\u53d8\u91cf\uff0c\u90a3\u4e48\u4f7f\u7528var\u4f1a\u751f\u6210\u4e00\u4e2a\u65b0\u7684\u5c40\u90e8\u53d8\u91cf\uff0c\u4ece\u800c\u907f\u514d\u4e0d\u5c0f\u5fc3\u4fee\u6539\u4e86\u5168\u5c40\u53d8\u91cf\u7684\u503c\u3002 \u6240\u4ee5\u6700\u597d\u7684\u4e60\u60ef\u505a\u6cd5\u662f\uff1a \u603b\u4f7f\u7528var\u6765\u5b9a\u4e49\u58f0\u660e\u4e00\u4e2a\u53d8\u91cf\u3002 &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; \u53d8\u91cf\u7684\u6709\u6548\u671f \u5728\u51fd\u6570\u4e2d\u5b9a\u4e49\u7684\u53d8\u91cf\u53ea\u80fd\u591f\u5728\u8be5\u51fd\u6570\u4e2d\u8bbf\u95ee\u3002\u5f53\u9000\u51fa\u8be5\u51fd\u6570\u65f6\uff0c\u53d8\u91cf\u5c31\u88ab\u9500\u6bc1\u4e86\u3002\u8fd9\u4e9b\u53d8\u91cf\u53eb\u505a\u672c\u5730\u53d8\u91cf\u3002\u4e0d\u540c\u51fd\u6570\u4e2d\u7684\u672c\u5730\u53d8\u91cf\u53ef\u4ee5\u540c\u540d\uff0c\u56e0\u4e3a\u6bcf\u4e00\u4e2a\u672c\u5730\u53d8\u91cf\u90fd\u53ea\u662f\u5728\u5b9a\u4e49\u5b83\u7684\u51fd\u6570\u4e2d\u6709\u6548\u3002 \u5982\u679c\u5728\u51fd\u6570\u5916\u9762\u5b9a\u4e49\u4e00\u4e2a\u53d8\u91cf\uff0c\u90a3\u4e48\u8be5\u9875\u9762\u4e0a\u7684\u6240\u6709\u51fd\u6570\u90fd\u53ef\u4ee5\u8bbf\u95ee\u8fd9\u4e2a\u53d8\u91cf\u3002\u8fd9\u4e2a\u53d8\u91cf\u7684\u6709\u6548\u671f\u4ece\u5b83\u88ab\u5b9a\u4e49\u5f00\u59cb\uff0c\u5230\u8be5\u9875\u9762\u88ab\u5173\u95ed\u4e3a\u6b62\u3002 \u6ce8\u610f\uff1a\u5728JavaScript\u4e2d\u53d8\u91cf\u662f\u53ef\u4ee5\u88ab\u91cd\u590d\u58f0\u660e\u7684\uff0c\u5e76\u4e14\u5f53\u53d8\u91cf\u88ab\u91cd\u590d\u58f0\u660e\u65f6\u5e76\u4e0d\u4f1a\u5931\u53bb\u5176\u539f\u5148\u7684\u503c\uff0c\u4f8b\u5982\uff1a [javascript] var myUrl = &#8220;http:\/\/www.prglab.com&#8221; var myUrl [\/javascript] \u8fd9\u4e24\u884c\u4ee3\u7801\u6267\u884c\u540e\uff0cmyUrl\u7136\u662fhttp:\/\/www.prglab.com\uff0c\u800c\u4e0d\u4f1a\u88ab\u7f6e\u7a7a\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":3,"menu_order":3,"comment_status":"open","ping_status":"open","template":"","meta":[],"_links":{"self":[{"href":"https:\/\/www.prglab.com\/blog\/wp-json\/wp\/v2\/pages\/10"}],"collection":[{"href":"https:\/\/www.prglab.com\/blog\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.prglab.com\/blog\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.prglab.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.prglab.com\/blog\/wp-json\/wp\/v2\/comments?post=10"}],"version-history":[{"count":8,"href":"https:\/\/www.prglab.com\/blog\/wp-json\/wp\/v2\/pages\/10\/revisions"}],"predecessor-version":[{"id":135,"href":"https:\/\/www.prglab.com\/blog\/wp-json\/wp\/v2\/pages\/10\/revisions\/135"}],"up":[{"embeddable":true,"href":"https:\/\/www.prglab.com\/blog\/wp-json\/wp\/v2\/pages\/3"}],"wp:attachment":[{"href":"https:\/\/www.prglab.com\/blog\/wp-json\/wp\/v2\/media?parent=10"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}