{"id":32492,"date":"2024-11-25T13:28:15","date_gmt":"2024-11-25T05:28:15","guid":{"rendered":"https:\/\/fwq.ai\/blog\/32492\/"},"modified":"2024-11-25T13:28:15","modified_gmt":"2024-11-25T05:28:15","slug":"javascript%e7%9a%84%e9%9d%a2%e5%90%91%e5%af%b9%e8%b1%a1%e5%9f%ba%e7%a1%80%e7%9f%a5%e8%af%86","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/32492\/","title":{"rendered":"JavaScript\u7684\u9762\u5411\u5bf9\u8c61\u57fa\u7840\u77e5\u8bc6"},"content":{"rendered":"<p>\u8fd1\u5e74\u6765\uff0cJavaScript \u8d8a\u6765\u8d8a\u53d7\u6b22\u8fce\uff0c\u90e8\u5206\u539f\u56e0\u662f\u5f00\u53d1\u4e86\u4e00\u4e9b\u5e93\uff0c\u4f7f\u90a3\u4e9b\u5c1a\u672a\u5b8c\u5168\u638c\u63e1\u6838\u5fc3\u8bed\u8a00\u7684\u4eba\u66f4\u5bb9\u6613\u521b\u5efa JavaScript \u5e94\u7528\u7a0b\u5e8f\/\u6548\u679c\u3002 <\/p>\n<p>\u867d\u7136\u5728\u8fc7\u53bb\uff0c\u4eba\u4eec\u666e\u904d\u8ba4\u4e3a javascript \u662f\u4e00\u79cd\u57fa\u7840\u8bed\u8a00\uff0c\u800c\u4e14\u975e\u5e38\u201c\u8349\u7387\u201d\uff0c\u6ca1\u6709\u771f\u6b63\u7684\u57fa\u7840\uff1b\u4f46\u73b0\u5728\u60c5\u51b5\u5df2\u4e0d\u518d\u5982\u6b64\uff0c\u5c24\u5176\u662f\u968f\u7740\u5927\u89c4\u6a21 web \u5e94\u7528\u7a0b\u5e8f\u548c json\uff08javascript \u5bf9\u8c61\u8868\u793a\u6cd5\uff09\u7b49\u201c\u9002\u5e94\u201d\u7684\u5f15\u5165\u3002 <\/p>\n<p>JavaScript \u53ef\u4ee5\u62e5\u6709\u9762\u5411\u5bf9\u8c61\u8bed\u8a00\u6240\u63d0\u4f9b\u7684\u6240\u6709\u529f\u80fd\uff0c\u5c3d\u7ba1\u9700\u8981\u4ed8\u51fa\u4e00\u4e9b\u8d85\u51fa\u672c\u6587\u8ba8\u8bba\u8303\u56f4\u7684\u989d\u5916\u5de5\u4f5c\u3002 <\/p>\n<h3>\u8ba9\u6211\u4eec\u521b\u5efa\u4e00\u4e2a\u5bf9\u8c61<\/h3>\n<pre>    function myObject(){\n    \n    };\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u606d\u559c\uff0c\u60a8\u521a\u521a\u521b\u5efa\u4e86\u4e00\u4e2a\u5bf9\u8c61\u3002\u521b\u5efa JavaScript \u5bf9\u8c61\u6709\u4e24\u79cd\u65b9\u6cd5\uff1a\u201c\u6784\u9020\u51fd\u6570\u201d\u548c\u201c\u6587\u5b57\u8868\u793a\u6cd5\u201d\u3002\u4e0a\u9762\u7684\u51fd\u6570\u662f\u4e00\u4e2a\u6784\u9020\u51fd\u6570\uff0c\u6211\u5c06\u5f88\u5feb\u89e3\u91ca\u5176\u4e2d\u7684\u533a\u522b\uff0c\u4f46\u5728\u6b64\u4e4b\u524d\uff0c\u8fd9\u662f\u4f7f\u7528\u6587\u5b57\u8868\u793a\u6cd5\u7684\u5bf9\u8c61\u5b9a\u4e49\u7684\u6837\u5b50\u3002<\/p>\n<pre>    var myObject = {\n    \n    };\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6587\u5b57\u662f\u540d\u79f0\u95f4\u8ddd\u7684\u9996\u9009\u9009\u9879\uff0c\u8fd9\u6837\u60a8\u7684 JavaScript \u4ee3\u7801\u5c31\u4e0d\u4f1a\u5e72\u6270\uff08\u53cd\u4e4b\u4ea6\u7136\uff09\u9875\u9762\u4e0a\u8fd0\u884c\u7684\u5176\u4ed6\u811a\u672c\uff0c\u5e76\u4e14\u5982\u679c\u60a8\u5c06\u6b64\u5bf9\u8c61\u7528\u4f5c\u5355\u4e2a\u5bf9\u8c61\u5e76\u4e14\u4e0d\u9700\u8981\u591a\u4e2a\u5bf9\u8c61\u5bf9\u8c61\u7684\u5b9e\u4f8b\uff0c\u800c\u5982\u679c\u60a8\u9700\u8981\u5728\u521b\u5efa\u5bf9\u8c61\u4e4b\u524d\u6267\u884c\u4e00\u4e9b\u521d\u59cb\u5de5\u4f5c\uff0c\u6216\u8005\u9700\u8981\u5bf9\u8c61\u7684\u591a\u4e2a\u5b9e\u4f8b\uff08\u5176\u4e2d\u6bcf\u4e2a\u5b9e\u4f8b\u90fd\u53ef\u4ee5\u5728\u811a\u672c\u7684\u751f\u547d\u5468\u671f\u5185\u66f4\u6539\uff09\uff0c\u5219\u9996\u9009\u6784\u9020\u51fd\u6570\u7c7b\u578b\u8868\u793a\u6cd5\u3002\u8ba9\u6211\u4eec\u7ee7\u7eed\u540c\u65f6\u6784\u5efa\u4e24\u4e2a\u5bf9\u8c61\uff0c\u4ee5\u4fbf\u6211\u4eec\u53ef\u4ee5\u89c2\u5bdf\u5dee\u5f02\u3002<\/p>\n<h3>\u5b9a\u4e49\u65b9\u6cd5\u548c\u5c5e\u6027<\/h3>\n<h4>\u6784\u9020\u51fd\u6570\u7248\u672c\uff1a<\/h4>\n<pre>    function myObject(){\n        this.iAm = 'an object';\n        this.whatAmI = function(){\n            alert('I am ' + this.iAm);\n        };\n    };\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h4>\u6587\u5b57\u7248\u672c\uff1a<\/h4>\n<pre>    var myObject = {\n        iAm : 'an object',\n        whatAmI : function(){\n            alert('I am ' + this.iAm);\n        }\n    }\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5bf9\u4e8e\u6bcf\u4e2a\u5bf9\u8c61\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u5c5e\u6027\u201ciAm\u201d\uff0c\u5176\u4e2d\u5305\u542b\u4e00\u4e2a\u5b57\u7b26\u4e32\u503c\uff0c\u8be5\u5b57\u7b26\u4e32\u503c\u5728\u6211\u4eec\u7684\u5bf9\u8c61\u65b9\u6cd5\u201cwhatAmI\u201d\u4e2d\u4f7f\u7528\uff0c\u8be5\u65b9\u6cd5\u4f1a\u53d1\u51fa\u8b66\u62a5\u6d88\u606f\u3002 <\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<blockquote><p>\n  \u5c5e\u6027\u662f\u5728\u5bf9\u8c61\u5185\u90e8\u521b\u5efa\u7684\u53d8\u91cf\uff0c\u65b9\u6cd5\u662f\u5728\u5bf9\u8c61\u5185\u90e8\u521b\u5efa\u7684\u51fd\u6570\u3002\n<\/p><\/blockquote>\n<p>\u73b0\u5728\u53ef\u80fd\u662f\u89e3\u91ca\u5982\u4f55\u4f7f\u7528\u5c5e\u6027\u548c\u65b9\u6cd5\u7684\u6700\u4f73\u65f6\u673a\uff08\u5c3d\u7ba1\u5982\u679c\u60a8\u719f\u6089\u5e93\uff0c\u60a8\u53ef\u80fd\u5df2\u7ecf\u8fd9\u6837\u505a\u4e86\uff09\u3002<\/p>\n<p>\u8981\u4f7f\u7528\u5c5e\u6027\uff0c\u9996\u5148\u8981\u8f93\u5165\u5b83\u6240\u5c5e\u7684\u5bf9\u8c61 &#8211; \u56e0\u6b64\u5728\u672c\u4f8b\u4e2d\u662f myObject &#8211; \u7136\u540e\u8981\u5f15\u7528\u5176\u5185\u90e8\u5c5e\u6027\uff0c\u8bf7\u5148\u52a0\u4e0a\u53e5\u53f7\uff0c\u7136\u540e\u8f93\u5165\u5c5e\u6027\u540d\u79f0\uff0c\u8fd9\u6837\u5b83\u6700\u7ec8\u770b\u8d77\u6765\u4f1a\u50cf myObject .iAm\uff08\u8fd9\u5c06\u8fd4\u56de\u201c\u4e00\u4e2a\u5bf9\u8c61\u201d\uff09\u3002<\/p>\n<p>\u5bf9\u4e8e\u65b9\u6cd5\u6765\u8bf4\uff0c\u9664\u4e86\u6267\u884c\u65b9\u6cd5\u4e4b\u5916\uff0c\u90fd\u662f\u4e00\u6837\u7684\uff0c\u5c31\u50cf\u4efb\u4f55\u51fd\u6570\u4e00\u6837\uff0c\u5fc5\u987b\u5728\u5176\u540e\u9762\u52a0\u4e0a\u62ec\u53f7\uff1b\u5426\u5219\uff0c\u60a8\u5c06\u53ea\u8fd4\u56de\u5bf9\u51fd\u6570\u7684\u5f15\u7528\uff0c\u800c\u4e0d\u662f\u51fd\u6570\u5b9e\u9645\u8fd4\u56de\u7684\u5185\u5bb9\u3002\u6240\u4ee5\u5b83\u770b\u8d77\u6765\u50cf myObject.whatAmI() \uff08\u8fd9\u4f1a\u63d0\u9192\u201c\u6211\u662f\u4e00\u4e2a\u5bf9\u8c61\u201d\uff09\u3002<\/p>\n<h4>\u73b0\u5728\u6765\u770b\u770b\u5dee\u5f02\uff1a<\/h4>\n<ul>\n<li>\u6784\u9020\u51fd\u6570\u5bf9\u8c61\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\u662f\u5728\u5176\u524d\u9762\u4f7f\u7528\u5173\u952e\u5b57\u201cthis\u201d\u5b9a\u4e49\u7684\uff0c\u800c\u5b57\u9762\u7248\u672c\u5219\u6ca1\u6709\u3002<\/li>\n<li>\u5728\u6784\u9020\u51fd\u6570\u5bf9\u8c61\u4e2d\uff0c\u5c5e\u6027\/\u65b9\u6cd5\u7684\u201c\u503c\u201d\u5728\u7b49\u53f7\u201c=\u201d\u4e4b\u540e\u5b9a\u4e49\uff0c\u800c\u5728\u5b57\u9762\u7248\u672c\u4e2d\uff0c\u5b83\u4eec\u5728\u5192\u53f7\u201c:\u201d\u4e4b\u540e\u5b9a\u4e49\u3002<\/li>\n<li>\u6784\u9020\u51fd\u6570\u53ef\u4ee5\u6709\uff08\u53ef\u9009\uff09\u5206\u53f7\u201c;\u201d\u5728\u6bcf\u4e2a\u5c5e\u6027\/\u65b9\u6cd5\u58f0\u660e\u7684\u672b\u5c3e\uff0c\u800c\u5728\u5b57\u9762\u7248\u672c\u4e2d\uff0c\u5982\u679c\u60a8\u6709\u591a\u4e2a\u5c5e\u6027\u6216\u65b9\u6cd5\uff0c\u5219\u5b83\u4eec\u5fc5\u987b\u7528\u9017\u53f7\u201c\uff0c\u201d\u5206\u9694\uff0c\u5e76\u4e14\u5b83\u4eec\u540e\u9762\u4e0d\u80fd\u6709\u5206\u53f7\uff0c\u5426\u5219 JavaScript \u5c06\u8fd4\u56de\u9519\u8bef\u3002<\/li>\n<\/ul>\n<p>\u8fd9\u4e24\u79cd\u7c7b\u578b\u7684\u5bf9\u8c61\u58f0\u660e\u7684\u4f7f\u7528\u65b9\u5f0f\u4e5f\u5b58\u5728\u5dee\u5f02\u3002<\/p>\n<p>\u8981\u4f7f\u7528\u5b57\u9762\u4e0a\u6807\u6ce8\u7684\u5bf9\u8c61\uff0c\u60a8\u53ea\u9700\u901a\u8fc7\u5f15\u7528\u5176\u53d8\u91cf\u540d\u79f0\u6765\u4f7f\u7528\u5b83\uff0c\u56e0\u6b64\u65e0\u8bba\u4f55\u65f6\u9700\u8981\u5b83\uff0c\u60a8\u90fd\u53ef\u4ee5\u901a\u8fc7\u952e\u5165\u6765\u8c03\u7528\u5b83\uff1b<\/p>\n<pre>    myObject.whatAmI();\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4f7f\u7528\u6784\u9020\u51fd\u6570\uff0c\u60a8\u9700\u8981\u9996\u5148\u5b9e\u4f8b\u5316\uff08\u521b\u5efa\u5bf9\u8c61\u7684\u65b0\u5b9e\u4f8b\uff09\uff1b\u60a8\u53ef\u4ee5\u901a\u8fc7\u8f93\u5165\u6765\u5b8c\u6210\u6b64\u64cd\u4f5c\uff1b<\/p>\n<pre>    var myNewObject = new myObject();\n    myNewObject.whatAmI();\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h3>\u4f7f\u7528\u6784\u9020\u51fd\u6570\u3002<\/h3>\n<p>\u8ba9\u6211\u4eec\u4f7f\u7528\u4e4b\u524d\u7684\u6784\u9020\u51fd\u6570\u5e76\u5728\u5176\u57fa\u7840\u4e0a\u8fdb\u884c\u6784\u5efa\uff0c\u4ee5\u4fbf\u5728\u5b9e\u4f8b\u5316\u5b83\u65f6\u6267\u884c\u4e00\u4e9b\u57fa\u672c\uff08\u4f46\u52a8\u6001\uff09\u64cd\u4f5c\u3002<\/p>\n<pre>    function myObject(){\n        this.iAm = 'an object';\n        this.whatAmI = function(){\n            alert('I am ' + this.iAm);\n        };\n    };\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5c31\u50cf\u4efb\u4f55 JavaScript \u51fd\u6570\u4e00\u6837\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u6784\u9020\u51fd\u6570\u4e2d\u4f7f\u7528\u53c2\u6570\uff1b<\/p>\n<pre>function myObject(what){\n\tthis.iAm = what;\n\tthis.whatAmI = function(language){\n\t\talert('I am ' + this.iAm + ' of the ' + language + ' language');\n\t};\n};\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u73b0\u5728\u8ba9\u6211\u4eec\u5b9e\u4f8b\u5316\u6211\u4eec\u7684\u5bf9\u8c61\u5e76\u8c03\u7528\u5b83\u7684 WhatAmI \u65b9\u6cd5\uff0c\u540c\u65f6\u586b\u5199\u6240\u9700\u7684\u5b57\u6bb5\u3002<\/p>\n<pre>    var myNewObject = new myObject('an object');\n    myNewObject.whatAmI('JavaScript');\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u5c06\u8b66\u544a\u201c\u6211\u662f JavaScript \u8bed\u8a00\u7684\u5bf9\u8c61\u3002\u201d<\/p>\n<h3>\u5b9e\u4f8b\u5316\u6216\u4e0d\u5b9e\u4f8b\u5316<\/h3>\n<p>\u6211\u4e4b\u524d\u63d0\u5230\u8fc7\u5bf9\u8c61\u6784\u9020\u51fd\u6570\u548c\u5bf9\u8c61\u6587\u5b57\u4e4b\u95f4\u7684\u5dee\u5f02\uff0c\u5f53\u5bf9\u5bf9\u8c61\u6587\u5b57\u8fdb\u884c\u66f4\u6539\u65f6\uff0c\u5b83\u4f1a\u5f71\u54cd\u6574\u4e2a\u811a\u672c\u4e2d\u7684\u8be5\u5bf9\u8c61\uff0c\u800c\u5f53\u6784\u9020\u51fd\u6570\u88ab\u5b9e\u4f8b\u5316\u7136\u540e\u5bf9\u5176\u8fdb\u884c\u66f4\u6539\u65f6\u5b9e\u4f8b\uff0c\u5b83\u4e0d\u4f1a\u5f71\u54cd\u8be5\u5bf9\u8c61\u7684\u4efb\u4f55\u5176\u4ed6\u5b9e\u4f8b\u3002\u8ba9\u6211\u4eec\u5c1d\u8bd5\u4e00\u4e2a\u4f8b\u5b50\uff1b<\/p>\n<p>\u9996\u5148\u6211\u4eec\u5c06\u521b\u5efa\u4e00\u4e2a\u5bf9\u8c61\u6587\u5b57\uff1b<\/p>\n<pre>\tvar myObjectLiteral = {\n    \tmyProperty : 'this is a property'\n    }\n    \n    \/\/alert current myProperty\n    alert(myObjectLiteral.myProperty); \/\/this will alert 'this is a property'\n    \n    \/\/change myProperty\n    myObjectLiteral.myProperty = 'this is a new property';\n    \n    \/\/alert current myProperty\n    alert(myObjectLiteral.myProperty); \/\/this will alert 'this is a new property', as expected\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5373\u4f7f\u60a8\u521b\u5efa\u4e00\u4e2a\u65b0\u53d8\u91cf\u5e76\u5c06\u5176\u6307\u5411\u8be5\u5bf9\u8c61\uff0c\u4e5f\u4f1a\u4ea7\u751f\u76f8\u540c\u7684\u6548\u679c\u3002<\/p>\n<pre>\tvar myObjectLiteral = {\n    \tmyProperty : 'this is a property'\n    }\n    \n    \/\/alert current myProperty\n    alert(myObjectLiteral.myProperty); \/\/this will alert 'this is a property'\n    \n    \/\/define new variable with object as value\n    var sameObject = myObjectLiteral;\n    \n    \/\/change myProperty\n    myObjectLiteral.myProperty = 'this is a new property';\n    \n    \/\/alert current myProperty\n    alert(sameObject.myProperty); \/\/this will still alert 'this is a new property'\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u73b0\u5728\u8ba9\u6211\u4eec\u5c1d\u8bd5\u4f7f\u7528\u6784\u9020\u51fd\u6570\u8fdb\u884c\u7c7b\u4f3c\u7684\u7ec3\u4e60\u3002<\/p>\n<pre>\t\/\/this is one other way of creating a Constructor function\n\tvar myObjectConstructor = function(){\n    \tthis.myProperty = 'this is a property'\n    }\n    \n    \/\/instantiate our Constructor\n    var constructorOne = new myObjectConstructor();\n    \n    \/\/instantiate a second instance of our Constructor\n    var constructorTwo = new myObjectConstructor();\n    \n    \/\/alert current myProperty of constructorOne instance\n    alert(constructorOne.myProperty); \/\/this will alert 'this is a property'\n     \n     \/\/alert current myProperty of constructorTwo instance\n    alert(constructorTwo.myProperty); \/\/this will alert 'this is a property'\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6b63\u5982\u9884\u671f\u7684\u90a3\u6837\uff0c\u4e24\u8005\u90fd\u8fd4\u56de\u6b63\u786e\u7684\u503c\uff0c\u4f46\u8ba9\u6211\u4eec\u66f4\u6539\u5176\u4e2d\u4e00\u4e2a\u5b9e\u4f8b\u7684 myProperty\u3002<\/p>\n<pre>\t\/\/this is one other way of creating a Constructor function\n\tvar myObjectConstructor = function(){\n    \tthis.myProperty = 'this is a property'\n    }\n    \n    \/\/instantiate our Constructor\n    var constructorOne = new myObjectConstructor();\n    \n    \/\/change myProperty of the first instance\n    constructorOne.myProperty = 'this is a new property';\n    \n    \/\/instantiate a second instance of our Constructor\n    var constructorTwo = new myObjectConstructor();\n    \n    \/\/alert current myProperty of constructorOne instance\n    alert(constructorOne.myProperty); \/\/this will alert 'this is a new property'\n     \n     \/\/alert current myProperty of constructorTwo instance\n    alert(constructorTwo.myProperty); \/\/this will still alert 'this is a property'\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ece\u8fd9\u4e2a\u793a\u4f8b\u4e2d\u53ef\u4ee5\u770b\u51fa\uff0c\u5373\u4f7f\u6211\u4eec\u66f4\u6539\u4e86 constructorOne \u7684\u5c5e\u6027\uff0c\u5b83\u4e5f\u6ca1\u6709\u5f71\u54cd myObjectConstructor\uff0c\u56e0\u6b64\u4e5f\u6ca1\u6709\u5f71\u54cd constructorTwo\u3002\u5373\u4f7f\u5728\u66f4\u6539 constructorOne \u7684 myProperty \u5c5e\u6027\u4e4b\u524d\u5b9e\u4f8b\u5316\u4e86 constructorTwo\uff0c\u5b83\u4ecd\u7136\u4e0d\u4f1a\u5f71\u54cd constructorTwo \u7684 myProperty \u5c5e\u6027\uff0c\u56e0\u4e3a\u5b83\u662f JavaScript \u5185\u5b58\u4e2d\u5b8c\u5168\u4e0d\u540c\u7684\u5bf9\u8c61\u5b9e\u4f8b\u3002<\/p>\n<p>\u90a3\u4e48\u60a8\u5e94\u8be5\u4f7f\u7528\u54ea\u4e00\u4e2a\u5462\uff1f\u597d\u5427\uff0c\u8fd9\u53d6\u51b3\u4e8e\u60c5\u51b5\uff0c\u5982\u679c\u60a8\u7684\u811a\u672c\u53ea\u9700\u8981\u4e00\u4e2a\u6b64\u7c7b\u5bf9\u8c61\uff08\u6b63\u5982\u60a8\u5c06\u5728\u672c\u6587\u672b\u5c3e\u7684\u793a\u4f8b\u4e2d\u770b\u5230\u7684\u90a3\u6837\uff09\uff0c\u5219\u4f7f\u7528\u5bf9\u8c61\u6587\u5b57\uff0c\u4f46\u5982\u679c\u60a8\u9700\u8981\u4e00\u4e2a\u5bf9\u8c61\u7684\u591a\u4e2a\u5b9e\u4f8b\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5b9e\u4f8b\u5f7c\u6b64\u72ec\u7acb\uff0c\u5e76\u4e14\u6839\u636e\u5176\u6784\u9020\u65b9\u5f0f\u53ef\u4ee5\u5177\u6709\u4e0d\u540c\u7684\u5c5e\u6027\u6216\u65b9\u6cd5\uff0c\u7136\u540e\u4f7f\u7528\u6784\u9020\u51fd\u6570\u3002<\/p>\n<h3>\u8fd9\u4e2a\u548c\u90a3\u4e2a<\/h3>\n<p>\u5728\u89e3\u91ca\u6784\u9020\u51fd\u6570\u65f6\uff0c\u51fa\u73b0\u4e86\u5f88\u591a\u201cthis\u201d\u5173\u952e\u5b57\uff0c\u6211\u60f3\u8fd9\u662f\u8ba8\u8bba\u4f5c\u7528\u57df\u7684\u66f4\u597d\u65f6\u673a\uff01<\/p>\n<p>\u73b0\u5728\u60a8\u53ef\u80fd\u4f1a\u95ee\u201c\u60a8\u6240\u8bf4\u7684\u8303\u56f4\u662f\u4ec0\u4e48\u201d\uff1f JavaScript \u4e2d\u7684\u4f5c\u7528\u57df\u662f\u57fa\u4e8e\u51fd\u6570\/\u5bf9\u8c61\u7684\uff0c\u56e0\u6b64\u8fd9\u610f\u5473\u7740\u5982\u679c\u60a8\u5728\u51fd\u6570\u4e4b\u5916\uff0c\u5219\u65e0\u6cd5\u4f7f\u7528\u5728\u51fd\u6570\u5185\u90e8\u5b9a\u4e49\u7684\u53d8\u91cf\uff08\u9664\u975e\u60a8\u4f7f\u7528\u95ed\u5305\uff09\u3002<\/p>\n<p>\u7136\u800c\uff0c\u5b58\u5728\u4f5c\u7528\u57df\u94fe\uff0c\u8fd9\u610f\u5473\u7740\u53e6\u4e00\u4e2a\u51fd\u6570\u5185\u7684\u51fd\u6570\u53ef\u4ee5\u8bbf\u95ee\u5176\u7236\u51fd\u6570\u4e2d\u5b9a\u4e49\u7684\u53d8\u91cf\u3002\u8ba9\u6211\u4eec\u770b\u4e00\u4e9b\u793a\u4f8b\u4ee3\u7801\u3002<\/p>\n<pre>&lt;script type=\"text\/javascript\"&gt;\n\nvar var1 = 'this is global and is available to everyone';\n\nfunction function1(){\n\n\tvar var2 = 'this is only available inside function1 and function2';\t\n\t\n\tfunction function2(){\n\t\n\t\tvar var3 = 'this is only available inside function2';\n\t\n\t}\t\t\n\t\n}\n\n&lt;\/script&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6b63\u5982\u4f60\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\u770b\u5230\u7684\uff0c var1 \u662f\u5728\u5168\u5c40\u5bf9\u8c61\u4e2d\u5b9a\u4e49\u7684\uff0c\u53ef\u7528\u4e8e\u6240\u6709\u51fd\u6570\u548c\u5bf9\u8c61\uff0c var2 \u662f\u5728 function1 \u4e2d\u5b9a\u4e49\u7684\uff0c\u53ef\u7528\u4e8e function1 \u548c function2\uff0c\u4f46\u662f\u5982\u679c\u4f60\u5c1d\u8bd5\u5f15\u7528\u4ece\u5168\u5c40\u5bf9\u8c61\u4e2d\u83b7\u53d6\u5b83\u4f1a\u7ed9\u51fa\u9519\u8bef\u201cvar2 \u672a\u5b9a\u4e49\u201d\uff0cvar3 \u53ea\u80fd\u7531 function2 \u8bbf\u95ee\u3002<\/p>\n<p>\u90a3\u4e48\u201cthis\u201d\u6307\u7684\u662f\u4ec0\u4e48\u5462\uff1f\u5728\u6d4f\u89c8\u5668\u4e2d\uff0c\u201cthis\u201d\u5f15\u7528\u7a97\u53e3\u5bf9\u8c61\uff0c\u56e0\u6b64\u4ece\u6280\u672f\u4e0a\u8bb2\uff0c\u7a97\u53e3\u662f\u6211\u4eec\u7684\u5168\u5c40\u5bf9\u8c61\u3002\u5982\u679c\u6211\u4eec\u5728\u4e00\u4e2a\u5bf9\u8c61\u5185\u90e8\uff0c\u201cthis\u201d\u5c06\u5f15\u7528\u8be5\u5bf9\u8c61\u672c\u8eab\uff0c\u4f46\u662f\u5982\u679c\u60a8\u5728\u4e00\u4e2a\u51fd\u6570\u5185\u90e8\uff0c\u8fd9\u4ecd\u7136\u4f1a\u5f15\u7528\u7a97\u53e3\u5bf9\u8c61\uff0c\u540c\u6837\uff0c\u5982\u679c\u60a8\u5728\u4e00\u4e2a\u5bf9\u8c61\u5185\u7684\u65b9\u6cd5\u5185\u90e8\uff0c\u201c this&#8217; \u5c06\u5f15\u7528\u8be5\u5bf9\u8c61\u3002<\/p>\n<p>\u7531\u4e8e\u6211\u4eec\u7684\u4f5c\u7528\u57df\u94fe\uff0c\u5982\u679c\u6211\u4eec\u4f4d\u4e8e\u5b50\u5bf9\u8c61\uff08\u5bf9\u8c61\u5185\u7684\u5bf9\u8c61\uff09\u5185\u90e8\uff0c\u201cthis\u201d\u5c06\u5f15\u7528\u5b50\u5bf9\u8c61\u800c\u4e0d\u662f\u7236\u5bf9\u8c61\u3002<\/p>\n<p>\u4f5c\u4e3a\u65c1\u6ce8\uff0c\u8fd8\u503c\u5f97\u8865\u5145\u7684\u662f\uff0c\u5f53\u4f7f\u7528 setInterval\u3001setTimeout \u548c eval \u7b49\u51fd\u6570\u65f6\uff0c\u5f53\u60a8\u901a\u8fc7\u5176\u4e2d\u4e4b\u4e00\u6267\u884c\u51fd\u6570\u6216\u65b9\u6cd5\u65f6\uff0c\u201cthis\u201d\u6307\u7684\u662f window \u5bf9\u8c61\uff0c\u56e0\u4e3a\u8fd9\u4e9b\u662f window \u7684\u65b9\u6cd5\uff0c\u6240\u4ee5 setInterval() \u548c window.setInterval() \u662f\u76f8\u540c\u7684\u3002<\/p>\n<p>\u597d\u5427\uff0c\u73b0\u5728\u6211\u4eec\u5df2\u7ecf\u89e3\u51b3\u4e86\u8fd9\u4e2a\u95ee\u9898\uff0c\u8ba9\u6211\u4eec\u505a\u4e00\u4e2a\u771f\u5b9e\u7684\u793a\u4f8b\u5e76\u521b\u5efa\u4e00\u4e2a\u8868\u5355\u9a8c\u8bc1\u5bf9\u8c61\uff01<\/p>\n<h3>\u73b0\u5b9e\u4e16\u754c\u7684\u7528\u6cd5\uff1a\u8868\u5355\u9a8c\u8bc1\u5bf9\u8c61<\/h3>\n<p>\u9996\u5148\u6211\u5fc5\u987b\u5411\u60a8\u4ecb\u7ecd\u6211\u4eec\u5c06\u521b\u5efa\u7684 addEvent \u51fd\u6570\uff0c\u5b83\u662f ECMAScript \u7684\uff08Firefox\u3001Safari \u7b49\uff09addEventListener() \u51fd\u6570\u548c Microsoft ActiveX Script \u7684 AttachEvent() \u51fd\u6570\u7684\u7ec4\u5408\u3002<\/p>\n<pre>    function addEvent(to, type, fn){\n        if(document.addEventListener){\n            to.addEventListener(type, fn, false);\n        } else if(document.attachEvent){\n            to.attachEvent('on'+type, fn);\n        } else {\n            to['on'+type] = fn;\n        }\t\n    };\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u5c06\u521b\u5efa\u4e00\u4e2a\u5177\u6709\u4e09\u4e2a\u53c2\u6570\u7684\u65b0\u51fd\u6570\uff0cto \u662f\u6211\u4eec\u5c06\u4e8b\u4ef6\u9644\u52a0\u5230\u7684 DOM \u5bf9\u8c61\uff0ctype \u662f\u4e8b\u4ef6\u7c7b\u578b\uff0cfn \u662f\u89e6\u53d1\u4e8b\u4ef6\u65f6\u8fd0\u884c\u7684\u51fd\u6570\u3002\u5b83\u9996\u5148\u68c0\u67e5\u662f\u5426\u652f\u6301 addEventListener\uff0c\u5982\u679c\u652f\u6301\uff0c\u5b83\u5c06\u4f7f\u7528\u5b83\uff0c\u5982\u679c\u4e0d\u652f\u6301\uff0c\u5b83\u5c06\u68c0\u67e5 AttachEvent\uff0c\u5982\u679c\u5176\u4ed6\u6240\u6709\u65b9\u6cd5\u90fd\u5931\u8d25\uff0c\u60a8\u53ef\u80fd\u6b63\u5728\u4f7f\u7528 IE5 \u6216\u540c\u6837\u8fc7\u65f6\u7684\u4e1c\u897f\uff0c\u56e0\u6b64\u6211\u4eec\u5c06\u4e8b\u4ef6\u76f4\u63a5\u6dfb\u52a0\u5230\u5176\u4e8b\u4ef6\u5c5e\u6027\u4e0a\uff08\u6ce8\u610f\uff1a\u7b2c\u4e09\u4e2a\u9009\u9879\u5c06\u8986\u76d6\u53ef\u80fd\u5df2\u9644\u52a0\u5230\u4e8b\u4ef6\u5c5e\u6027\u7684\u4efb\u4f55\u73b0\u6709\u51fd\u6570\uff0c\u800c\u524d\u4e24\u4e2a\u9009\u9879\u4f1a\u5c06\u5176\u4f5c\u4e3a\u9644\u52a0\u51fd\u6570\u6dfb\u52a0\u5230\u5176\u4e8b\u4ef6\u5c5e\u6027\u4e2d\uff09\u3002<\/p>\n<p>\u73b0\u5728\u8ba9\u6211\u4eec\u8bbe\u7f6e\u6211\u4eec\u7684\u6587\u6863\uff0c\u4f7f\u5176\u4e0e\u60a8\u5f00\u53d1 jQuery \u5185\u5bb9\u65f6\u53ef\u80fd\u770b\u5230\u7684\u7c7b\u4f3c\u3002<\/p>\n<p>\u5728 jQuery \u4e2d\u4f60\u4f1a\u6709\uff1b<\/p>\n<pre>    $(document).ready(function(){\n        \/\/all our code that runs after the page is ready goes here\n    });\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4f7f\u7528\u6211\u4eec\u7684 addEvent \u51fd\u6570\uff1b<\/p>\n<pre>    addEvent(window, 'load', function(){\n\t\t\/\/all our code that runs after the page is ready goes here\n\t});\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u73b0\u5728\u6211\u4eec\u7684 Form \u5bf9\u8c61\u3002<\/p>\n<pre>var Form = {\n\n\tvalidClass : 'valid',\n\t\n\tfname : {\n\t\tminLength : 1,\t\t\n\t\tmaxLength : 15,\t\n\t\tfieldName : 'First Name'\n\t},\n    \n\tlname : {\n\t\tminLength : 1,\t\t\n\t\tmaxLength : 25,\n\t\tfieldName : 'Last Name'\n\t},\n\t\n    \n\tvalidateLength : function(formEl, type){\n\t\tif(formEl.value.length &amp;gt; type.maxLength || formEl.value.length \n\n&lt;p&gt;\u6240\u4ee5\u8fd9\u662f\u975e\u5e38\u57fa\u672c\u7684\uff0c\u4f46\u53ef\u4ee5\u5f88\u5bb9\u6613\u5730\u6269\u5c55\u3002&lt;\/p&gt;\n\n&lt;p&gt;\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u6211\u4eec\u9996\u5148\u521b\u5efa\u4e00\u4e2a\u65b0\u5c5e\u6027\uff0c\u5b83\u53ea\u662f\u201c\u6709\u6548\u201dCSS \u7c7b\u7684\u5b57\u7b26\u4e32\u540d\u79f0\uff0c\u5f53\u5e94\u7528\u4e8e\u8868\u5355\u5b57\u6bb5\u65f6\uff0c\u4f1a\u6dfb\u52a0\u6709\u6548\u7684\u6548\u679c\uff0c\u4f8b\u5982\u7eff\u8272\u8fb9\u6846\u3002\u6211\u4eec\u8fd8\u5b9a\u4e49\u4e86\u4e24\u4e2a\u5b50\u5bf9\u8c61\uff0cfname\u548clname\uff0c\u56e0\u6b64\u6211\u4eec\u53ef\u4ee5\u5b9a\u4e49\u5b83\u4eec\u81ea\u5df1\u7684\u5c5e\u6027\uff0c\u8fd9\u4e9b\u5c5e\u6027\u53ef\u4ee5\u88ab\u5176\u4ed6\u5730\u65b9\u7684\u65b9\u6cd5\u4f7f\u7528\uff0c\u8fd9\u4e9b\u5c5e\u6027\u662fminLength\uff0c\u8fd9\u662f\u8fd9\u4e9b\u5b57\u6bb5\u53ef\u4ee5\u62e5\u6709\u7684\u6700\u5c0f\u5b57\u7b26\u6570\uff0c maxLength \u662f\u5b57\u6bb5\u53ef\u4ee5\u62e5\u6709\u7684\u6700\u5927\u5b57\u7b26\u6570\uff0c\u800c fieldName \u5b9e\u9645\u4e0a\u5e76\u6ca1\u6709\u88ab\u4f7f\u7528\uff0c\u4f46\u53ef\u4ee5\u7528\u4e8e\u8bf8\u5982\u5728\u9519\u8bef\u6d88\u606f\u4e2d\u4f7f\u7528\u7528\u6237\u53cb\u597d\u7684\u5b57\u7b26\u4e32\u8bc6\u522b\u5b57\u6bb5\u4e4b\u7c7b\u7684\u4e8b\u60c5\uff08\u4f8b\u5982\u201c\u540d\u5b57\u5b57\u6bb5\u201d\uff09\u662f\u5fc5\u9700\u7684\u3002')\u3002&lt;\/p&gt;\n\n&lt;p&gt;\u63a5\u4e0b\u6765\u6211\u4eec\u521b\u5efa\u4e00\u4e2a validateLength \u65b9\u6cd5\uff0c\u5b83\u63a5\u53d7\u4e24\u4e2a\u53c2\u6570\uff1a formEl \u8981\u9a8c\u8bc1\u7684 DOM \u5143\u7d20\u548c type \uff0c\u5b83\u5f15\u7528\u8981\u4f7f\u7528\u7684\u5b50\u5bf9\u8c61\u4e4b\u4e00\uff08\u5373 fname \u6216 lname\uff09\u3002\u8be5\u51fd\u6570\u68c0\u67e5\u5b57\u6bb5\u7684\u957f\u5ea6\u662f\u5426\u5728 minLength \u548c maxLength \u8303\u56f4\u4e4b\u95f4\uff0c\u5982\u679c\u4e0d\u662f\uff0c\u90a3\u4e48\u6211\u4eec\u4ece\u5143\u7d20\u4e2d\u5220\u9664\u6709\u6548\u7c7b\uff08\u5982\u679c\u5b58\u5728\uff09\u5e76\u8fd4\u56de false\uff0c\u5426\u5219\u5982\u679c\u662f\uff0c\u90a3\u4e48\u6211\u4eec\u6dfb\u52a0\u6709\u6548\u7c7b\u5e76\u8fd4\u56de\u6b63\u786e\u3002&lt;\/p&gt;\n\n&lt;p&gt;\u7136\u540e\u6211\u4eec\u6709\u4e00\u4e2a validateEmail \u65b9\u6cd5\uff0c\u5b83\u63a5\u53d7 DOM \u5143\u7d20\u4f5c\u4e3a\u53c2\u6570\uff0c\u7136\u540e\u6211\u4eec\u6839\u636e\u7535\u5b50\u90ae\u4ef6\u7c7b\u578b\u6b63\u5219\u8868\u8fbe\u5f0f\u6d4b\u8bd5\u8fd9\u4e2a DOM \u5143\u7d20\u503c\uff1b\u5982\u679c\u901a\u8fc7\uff0c\u6211\u4eec\u518d\u6b21\u6dfb\u52a0\u6211\u4eec\u7684\u7c7b\u5e76\u8fd4\u56de true\uff0c\u53cd\u4e4b\u4ea6\u7136\u3002&lt;\/p&gt;\n\n&lt;p&gt;\u6700\u540e\u6211\u4eec\u6709\u4e00\u4e2a getSubmit \u65b9\u6cd5\u3002\u8be5\u65b9\u6cd5\u83b7\u5f97\u8868\u5355\u7684 id\uff0c\u7136\u540e\u5faa\u73af\u904d\u5386\u6307\u5b9a\u8868\u5355\u5185\u7684\u6240\u6709\u8f93\u5165\u5143\u7d20\uff0c\u4ee5\u67e5\u627e\u54ea\u4e00\u4e2a\u5177\u6709\u63d0\u4ea4\u7c7b\u578b (type=\"submit\")\u3002\u6b64\u65b9\u6cd5\u7684\u539f\u56e0\u662f\u8fd4\u56de\u63d0\u4ea4\u6309\u94ae\uff0c\u4ee5\u4fbf\u6211\u4eec\u53ef\u4ee5\u7981\u7528\u5b83\uff0c\u76f4\u5230\u8868\u5355\u51c6\u5907\u597d\u63d0\u4ea4\u3002&lt;\/p&gt;\n\n&lt;p&gt;\u8ba9\u6211\u4eec\u8ba9\u8fd9\u4e2a\u9a8c\u8bc1\u5668\u5bf9\u8c61\u5728\u771f\u5b9e\u7684\u8868\u5355\u4e0a\u5de5\u4f5c\u3002\u9996\u5148\u6211\u4eec\u9700\u8981 HTML\u3002&lt;\/p&gt;\n\n&lt;pre class=\"brush:javascript;toolbal:false;\"&gt;    \n    \n    <\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 First Name<br \/>\n<br \/> Last Name<br \/>\n<br \/> Email<br \/>\n <\/p>\n<p>\u73b0\u5728\u8ba9\u6211\u4eec\u4f7f\u7528 JavaScript \u8bbf\u95ee\u8fd9\u4e9b\u8f93\u5165\u5bf9\u8c61\uff0c\u5e76\u5728\u8868\u5355\u63d0\u4ea4\u65f6\u9a8c\u8bc1\u5b83\u4eec\u3002<\/p>\n<pre>addEvent(window, 'load', function(){\n\t\n\t\n\tvar ourForm = document.getElementById('ourForm');\t\n\tvar submit_button = Form.getSubmit('ourForm');\n\tsubmit_button.disabled = 'disabled';\n\t\n\tfunction checkForm(){\n\t\tvar inputs = ourForm.getElementsByTagName('input');\n\t\tif(Form.validateLength(inputs[0], Form.fname)){\n\t\t\tif(Form.validateLength(inputs[1], Form.lname)){\n\t\t\t\tif(Form.validateEmail(inputs[2])){ \t\t\t\t\t \n                     \n\t\t\t\t\t\tsubmit_button.disabled = false;\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\t\n\t\tsubmit_button.disabled = 'disabled';\n\t\treturn false;\n\t\t\n\t};\n\t\n\tcheckForm();\t\t\n\taddEvent(ourForm, 'keyup', checkForm);\n\taddEvent(ourForm, 'submit', checkForm);\n      \n\t\n});\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8ba9\u6211\u4eec\u5206\u89e3\u4e00\u4e0b\u8fd9\u6bb5\u4ee3\u7801\u3002<\/p>\n<p>\u6211\u4eec\u5c06\u4ee3\u7801\u5305\u88c5\u5728 addEvent \u51fd\u6570\u4e2d\uff0c\u4ee5\u4fbf\u5728\u52a0\u8f7d\u7a97\u53e3\u65f6\u8fd0\u884c\u6b64\u811a\u672c\u3002\u9996\u5148\uff0c\u6211\u4eec\u4f7f\u7528\u8868\u5355 ID \u83b7\u53d6\u8868\u5355\u5e76\u5c06\u5176\u653e\u5165\u540d\u4e3a ourForm \u7684\u53d8\u91cf\u4e2d\uff0c\u7136\u540e\u83b7\u53d6\u63d0\u4ea4\u6309\u94ae\uff08\u4f7f\u7528\u8868\u5355\u5bf9\u8c61 getSubmit \u65b9\u6cd5\uff09\u5e76\u5c06\u5176\u653e\u5165\u540d\u4e3a submit_button \u7684\u53d8\u91cf\u4e2d\uff0c\u7136\u540e\u8bbe\u7f6e\u63d0\u4ea4\u6309\u94ae\u7981\u7528\u5c5e\u6027\u4e3a\u201c\u7981\u7528\u201d\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\u6211\u4eec\u5b9a\u4e49\u4e00\u4e2a checkForm \u51fd\u6570\u3002\u8fd9\u4f1a\u5c06\u8868\u5355\u5b57\u6bb5\u5185\u7684\u6240\u6709\u8f93\u5165\u5b58\u50a8\u4e3a\u4e00\u4e2a\u6570\u7ec4\uff0c\u5e76\u5c06\u5176\u9644\u52a0\u5230\u4e00\u4e2a\u540d\u4e3a..\u4f60\u731c\u5bf9\u4e86\u7684\u53d8\u91cf.. inputs\uff01\u7136\u540e\u5b83\u5b9a\u4e49\u4e86\u4e00\u4e9b\u5d4c\u5957\u7684 if \u8bed\u53e5\uff0c\u8fd9\u4e9b\u8bed\u53e5\u6839\u636e\u6211\u4eec\u7684 Form \u65b9\u6cd5\u6d4b\u8bd5\u8f93\u5165\u6570\u7ec4\u5185\u7684\u6bcf\u4e2a\u5b57\u6bb5\u3002\u8fd9\u5c31\u662f\u6211\u4eec\u5728\u65b9\u6cd5\u4e2d\u8fd4\u56de true \u6216 false \u7684\u539f\u56e0\uff0c\u56e0\u6b64\u5982\u679c\u5b83\u8fd4\u56de true\uff0c\u6211\u4eec\u5c06\u4f20\u9012\u8be5 if \u8bed\u53e5\u5e76\u7ee7\u7eed\u6267\u884c\u4e0b\u4e00\u4e2a\uff0c\u4f46\u5982\u679c\u5b83\u8fd4\u56de false\uff0c\u6211\u4eec\u5c06\u9000\u51fa if \u8bed\u53e5\u3002<\/p>\n<p>\u6839\u636e\u6211\u4eec\u7684\u51fd\u6570\u5b9a\u4e49\uff0c\u6211\u4eec\u5728\u9875\u9762\u6700\u521d\u52a0\u8f7d\u65f6\u6267\u884c checkForm \u51fd\u6570\uff0c\u5e76\u5c06\u8be5\u51fd\u6570\u9644\u52a0\u5230 keyup \u4e8b\u4ef6\u548c\u63d0\u4ea4\u4e8b\u4ef6\u3002<\/p>\n<p>\u60a8\u53ef\u80fd\u4f1a\u95ee\uff0c\u5982\u679c\u6211\u4eec\u7981\u7528\u4e86\u63d0\u4ea4\u6309\u94ae\uff0c\u4e3a\u4ec0\u4e48\u8fd8\u8981\u9644\u52a0\u63d0\u4ea4\u3002\u597d\u5427\uff0c\u5982\u679c\u60a8\u4e13\u6ce8\u4e8e\u8f93\u5165\u5b57\u6bb5\u5e76\u6309\u4e0b Enter \u952e\uff0c\u5b83\u5c06\u5c1d\u8bd5\u63d0\u4ea4\u8868\u5355\uff0c\u6211\u4eec\u9700\u8981\u5bf9\u6b64\u8fdb\u884c\u6d4b\u8bd5\uff0c\u56e0\u6b64\u6211\u4eec\u7684 checkForm \u51fd\u6570\u8fd4\u56de true\uff08\u63d0\u4ea4\u8868\u5355\uff09\u6216 false\uff08\u4e0d\u63d0\u4ea4\uff09\u5f62\u5f0f\uff09\u3002<\/p>\n<h3>\u7ed3\u8bba<\/h3>\n<p>\u56e0\u6b64\uff0c\u6211\u4eec\u5b66\u4e60\u4e86\u5982\u4f55\u5728 JavaScript \u4e2d\u5b9a\u4e49\u4e0d\u540c\u7684\u5bf9\u8c61\u7c7b\u578b\u5e76\u5728\u5176\u4e2d\u521b\u5efa\u5c5e\u6027\u548c\u65b9\u6cd5\u3002\u6211\u4eec\u8fd8\u5b66\u4e60\u4e86\u4e00\u4e2a\u6f02\u4eae\u7684 addEvent \u51fd\u6570\uff0c\u5e76\u5728\u57fa\u672c\u7684\u73b0\u5b9e\u793a\u4f8b\u4e2d\u4f7f\u7528\u6211\u4eec\u7684\u5bf9\u8c61\u3002<\/p>\n<p>\u8fd9\u5c31\u662f JavaScript \u9762\u5411\u5bf9\u8c61\u7684\u57fa\u7840\u77e5\u8bc6\u3002\u5e0c\u671b\u8fd9\u53ef\u4ee5\u8ba9\u60a8\u5f00\u59cb\u6784\u5efa\u81ea\u5df1\u7684 JavaScript \u5e93\uff01\u5982\u679c\u60a8\u559c\u6b22\u8fd9\u7bc7\u6587\u7ae0\u5e76\u5bf9\u5176\u4ed6 JavaScript \u76f8\u5173\u4e3b\u9898\u611f\u5174\u8da3\uff0c\u8bf7\u5c06\u5b83\u4eec\u53d1\u5e03\u5728\u8bc4\u8bba\u4e2d\uff0c\u6211\u5f88\u4e50\u610f\u7ee7\u7eed\u64b0\u5199\u5b83\u4eec\u3002\u611f\u8c22\u60a8\u7684\u9605\u8bfb\u3002<\/p>\n<p>\u4e3a\u4ec0\u4e48\u4e0d\u770b\u770b CodeCanyon \u4e0a\u7684 JavaScript \u9879\u76ee\u8303\u56f4\u3002\u60a8\u53ef\u4ee5\u627e\u5230\u7528\u4e8e\u521b\u5efa\u6ed1\u5757\u3001\u5012\u8ba1\u65f6\u3001\u52a0\u8f7d\u5668\u548c\u4e0a\u4f20\u5668\u7b49\u7684\u811a\u672c\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/164\/169362487154932.png\" class=\"aligncenter\" title=\"JavaScript\u7684\u9762\u5411\u5bf9\u8c61\u57fa\u7840\u77e5\u8bc6\u63d2\u56fe\" alt=\"JavaScript\u7684\u9762\u5411\u5bf9\u8c61\u57fa\u7840\u77e5\u8bc6\u63d2\u56fe\" \/><\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fJavaScript\u7684\u9762\u5411\u5bf9\u8c61\u57fa\u7840\u77e5\u8bc6\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd1\u5e74\u6765\uff0cJavaScript \u8d8a\u6765\u8d8a\u53d7\u6b22\u8fce\uff0c\u90e8\u5206\u539f\u56e0\u662f\u5f00\u53d1\u4e86\u4e00\u4e9b\u5e93\uff0c\u4f7f\u90a3\u4e9b\u5c1a\u672a\u5b8c\u5168\u638c\u63e1\u6838\u5fc3\u8bed\u8a00\u7684\u4eba\u66f4\u5bb9\u6613\u521b\u5efa JavaScript \u5e94\u7528\u7a0b\u5e8f\/\u6548\u679c\u3002 \u867d\u7136\u5728\u8fc7\u53bb\uff0c\u4eba\u4eec\u666e\u904d\u8ba4\u4e3a javascript \u662f\u4e00\u79cd\u57fa\u7840\u8bed\u8a00\uff0c\u800c\u4e14\u975e\u5e38\u201c\u8349\u7387\u201d\uff0c\u6ca1\u6709\u771f\u6b63\u7684\u57fa\u7840\uff1b\u4f46\u73b0\u5728\u60c5\u51b5\u5df2\u4e0d\u518d\u5982\u6b64\uff0c\u5c24\u5176\u662f\u968f\u7740\u5927\u89c4\u6a21 web \u5e94\u7528\u7a0b\u5e8f\u548c json\uff08javascript \u5bf9\u8c61\u8868\u793a\u6cd5\uff09\u7b49\u201c\u9002\u5e94\u201d\u7684\u5f15\u5165\u3002 JavaScript \u53ef\u4ee5\u62e5\u6709\u9762\u5411\u5bf9\u8c61\u8bed\u8a00\u6240\u63d0\u4f9b\u7684\u6240\u6709\u529f\u80fd\uff0c\u5c3d\u7ba1\u9700\u8981\u4ed8\u51fa\u4e00\u4e9b\u8d85\u51fa\u672c\u6587\u8ba8\u8bba\u8303\u56f4\u7684\u989d\u5916\u5de5\u4f5c\u3002 \u8ba9\u6211\u4eec\u521b\u5efa\u4e00\u4e2a\u5bf9\u8c61 function myObject(){ }; \u767b\u5f55\u540e\u590d\u5236 \u606d\u559c\uff0c\u60a8\u521a\u521a\u521b\u5efa\u4e86\u4e00\u4e2a\u5bf9\u8c61\u3002\u521b\u5efa JavaScript \u5bf9\u8c61\u6709\u4e24\u79cd\u65b9\u6cd5\uff1a\u201c\u6784\u9020\u51fd\u6570\u201d\u548c\u201c\u6587\u5b57\u8868\u793a\u6cd5\u201d\u3002\u4e0a\u9762\u7684\u51fd\u6570\u662f\u4e00\u4e2a\u6784\u9020\u51fd\u6570\uff0c\u6211\u5c06\u5f88\u5feb\u89e3\u91ca\u5176\u4e2d\u7684\u533a\u522b\uff0c\u4f46\u5728\u6b64\u4e4b\u524d\uff0c\u8fd9\u662f\u4f7f\u7528\u6587\u5b57\u8868\u793a\u6cd5\u7684\u5bf9\u8c61\u5b9a\u4e49\u7684\u6837\u5b50\u3002 var myObject = { }; \u767b\u5f55\u540e\u590d\u5236 \u6587\u5b57\u662f\u540d\u79f0\u95f4\u8ddd\u7684\u9996\u9009\u9009\u9879\uff0c\u8fd9\u6837\u60a8\u7684 JavaScript \u4ee3\u7801\u5c31\u4e0d\u4f1a\u5e72\u6270\uff08\u53cd\u4e4b\u4ea6\u7136\uff09\u9875\u9762\u4e0a\u8fd0\u884c\u7684\u5176\u4ed6\u811a\u672c\uff0c\u5e76\u4e14\u5982\u679c\u60a8\u5c06\u6b64\u5bf9\u8c61\u7528\u4f5c\u5355\u4e2a\u5bf9\u8c61\u5e76\u4e14\u4e0d\u9700\u8981\u591a\u4e2a\u5bf9\u8c61\u5bf9\u8c61\u7684\u5b9e\u4f8b\uff0c\u800c\u5982\u679c\u60a8\u9700\u8981\u5728\u521b\u5efa\u5bf9\u8c61\u4e4b\u524d\u6267\u884c\u4e00\u4e9b\u521d\u59cb\u5de5\u4f5c\uff0c\u6216\u8005\u9700\u8981\u5bf9\u8c61\u7684\u591a\u4e2a\u5b9e\u4f8b\uff08\u5176\u4e2d\u6bcf\u4e2a\u5b9e\u4f8b\u90fd\u53ef\u4ee5\u5728\u811a\u672c\u7684\u751f\u547d\u5468\u671f\u5185\u66f4\u6539\uff09\uff0c\u5219\u9996\u9009\u6784\u9020\u51fd\u6570\u7c7b\u578b\u8868\u793a\u6cd5\u3002\u8ba9\u6211\u4eec\u7ee7\u7eed\u540c\u65f6\u6784\u5efa\u4e24\u4e2a\u5bf9\u8c61\uff0c\u4ee5\u4fbf\u6211\u4eec\u53ef\u4ee5\u89c2\u5bdf\u5dee\u5f02\u3002 \u5b9a\u4e49\u65b9\u6cd5\u548c\u5c5e\u6027 \u6784\u9020\u51fd\u6570\u7248\u672c\uff1a function myObject(){ this.iAm = &#8216;an object&#8217;; this.whatAmI = function(){ alert(&#8216;I am &#8216; + this.iAm); }; }; \u767b\u5f55\u540e\u590d\u5236 \u767b\u5f55\u540e\u590d\u5236 \u6587\u5b57\u7248\u672c\uff1a var myObject = { [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-32492","post","type-post","status-publish","format-standard","hentry","category-cms"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/32492","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=32492"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/32492\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=32492"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=32492"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=32492"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}