{"id":5659,"date":"2023-01-06T11:13:20","date_gmt":"2023-01-06T03:13:20","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=5659"},"modified":"2023-01-06T11:13:20","modified_gmt":"2023-01-06T03:13:20","slug":"%e4%bd%bf%e7%94%a8react-js%e4%be%86%e9%a9%97%e8%ad%89%e8%bb%8a%e7%89%8c%e8%99%9f%e7%a2%bc%e7%9a%84%e6%9c%89%e6%95%88%e6%80%a7","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/react-js\/%e4%bd%bf%e7%94%a8react-js%e4%be%86%e9%a9%97%e8%ad%89%e8%bb%8a%e7%89%8c%e8%99%9f%e7%a2%bc%e7%9a%84%e6%9c%89%e6%95%88%e6%80%a7\/","title":{"rendered":"\u4f7f\u7528React.JS\u4f86\u9a57\u8b49\u8eca\u724c\u865f\u78bc\u7684\u6709\u6548\u6027"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"React.JS, isValidLicensePlate\"><\/p>\n<h1>\u4f7f\u7528 React.JS \u5224\u65b7\u662f\u5426\u70ba\u7b26\u5408\u8eca\u724c\u865f\u78bc<\/h1>\n<p>\u8eca\u724c\u865f\u78bc\u662f\u6bcf\u500b\u8eca\u4e3b\u5fc5\u9808\u64c1\u6709\u7684\u8b58\u5225\u865f\u78bc\uff0c\u5b83\u662f\u7531\u570b\u5bb6\u767c\u653e\u7684\u552f\u4e00\u8b58\u5225\u865f\u78bc\uff0c\u53ef\u4ee5\u7528\u4f86\u8b58\u5225\u8eca\u8f1b\u7684\u6240\u6709\u8005\u3002\u5728\u73fe\u4eca\u7684\u793e\u6703\u4e2d\uff0c\u8eca\u724c\u865f\u78bc\u7684\u91cd\u8981\u6027\u4e0d\u8a00\u800c\u55bb\uff0c\u56e0\u6b64\uff0c\u8eca\u724c\u865f\u78bc\u7684\u6aa2\u67e5\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002<\/p>\n<p>React.JS \u662f\u4e00\u500b\u7528\u65bc\u69cb\u5efa\u7528\u6236\u7aef\u61c9\u7528\u7a0b\u5e8f\u7684 JavaScript \u6846\u67b6\uff0c\u5b83\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u5feb\u901f\u69cb\u5efa\u51fa\u9ad8\u54c1\u8cea\u7684\u7528\u6236\u7aef\u61c9\u7528\u7a0b\u5e8f\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5011\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528 React.JS \u4f86\u6aa2\u67e5\u8eca\u724c\u865f\u78bc\u662f\u5426\u7b26\u5408\u898f\u5b9a\u3002<\/p>\n<h2>\u4f7f\u7528 React.JS \u5224\u65b7\u662f\u5426\u70ba\u7b26\u5408\u8eca\u724c\u865f\u78bc<\/h2>\n<p>\u9996\u5148\uff0c\u6211\u5011\u9700\u8981\u5275\u5efa\u4e00\u500b React \u7d44\u4ef6\uff0c\u7528\u65bc\u6aa2\u67e5\u8eca\u724c\u865f\u78bc\u662f\u5426\u7b26\u5408\u898f\u5b9a\u3002\u6211\u5011\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u78bc\u4f86\u5275\u5efa\u4e00\u500b\u7c21\u55ae\u7684 React \u7d44\u4ef6\uff1a<\/p>\n<pre class=\"brush: javascript\">\nclass IsValidLicensePlate extends React.Component {\n  constructor(props) {\n    super(props);\n    this.state = {\n      licensePlate: ''\n    };\n  }\n\n  isValidLicensePlate(licensePlate) {\n    \/\/ \u6aa2\u67e5\u8eca\u724c\u865f\u78bc\u662f\u5426\u7b26\u5408\u898f\u5b9a\n  }\n\n  render() {\n    return (\n      <div>\n        <input\n          type=\"text\"\n          value={this.state.licensePlate}\n          onChange={e => this.setState({ licensePlate: e.target.value })}\n        \/>\n        <button onClick={() => this.isValidLicensePlate(this.state.licensePlate)}>\n          \u6aa2\u67e5\u8eca\u724c\u865f\u78bc\n        <\/button>\n      <\/div>\n    );\n  }\n}\n<\/pre>\n<p>\u5728\u4e0a\u9762\u7684\u4ee3\u78bc\u4e2d\uff0c\u6211\u5011\u5275\u5efa\u4e86\u4e00\u500b\u540d\u70ba <code>IsValidLicensePlate<\/code> \u7684 React \u7d44\u4ef6\uff0c\u5b83\u6709\u4e00\u500b <code>isValidLicensePlate<\/code> \u65b9\u6cd5\uff0c\u7528\u65bc\u6aa2\u67e5\u8eca\u724c\u865f\u78bc\u662f\u5426\u7b26\u5408\u898f\u5b9a\u3002<\/p>\n<p>\u63a5\u4e0b\u4f86\uff0c\u6211\u5011\u9700\u8981\u5be6\u73fe <code>isValidLicensePlate<\/code> \u65b9\u6cd5\uff0c\u4ee5\u4fbf\u6aa2\u67e5\u8eca\u724c\u865f\u78bc\u662f\u5426\u7b26\u5408\u898f\u5b9a\u3002\u6211\u5011\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u78bc\u4f86\u5be6\u73fe\u8a72\u65b9\u6cd5\uff1a<\/p>\n<pre class=\"brush: javascript\">\nisValidLicensePlate(licensePlate) {\n  const regex = \/^[A-Z]{2}[0-9]{4}$\/;\n  return regex.test(licensePlate);\n}\n<\/pre>\n<p>\u5728\u4e0a\u9762\u7684\u4ee3\u78bc\u4e2d\uff0c\u6211\u5011\u4f7f\u7528\u4e86\u6b63\u5247\u8868\u9054\u5f0f\u4f86\u6aa2\u67e5\u8eca\u724c\u865f\u78bc\u662f\u5426\u7b26\u5408\u898f\u5b9a\u3002\u5982\u679c\u8eca\u724c\u865f\u78bc\u7b26\u5408\u898f\u5b9a\uff0c\u5247\u8fd4\u56de <code>true<\/code>\uff0c\u5426\u5247\u8fd4\u56de <code>false<\/code>\u3002<\/p>\n<p>\u6700\u5f8c\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u78bc\u4f86\u6e2c\u8a66\u6211\u5011\u7684 React \u7d44\u4ef6\uff1a<\/p>\n<pre class=\"brush: javascript\">\nconst licensePlate = 'AB1234';\nconst isValid = IsValidLicensePlate.isValidLicensePlate(licensePlate);\nconsole.log(isValid); \/\/ true\n<\/pre>\n<p>\u5728\u4e0a\u9762\u7684\u4ee3\u78bc\u4e2d\uff0c\u6211\u5011\u6e2c\u8a66\u4e86\u4e00\u500b\u7b26\u5408\u898f\u5b9a\u7684\u8eca\u724c\u865f\u78bc\uff0c\u6e2c\u8a66\u7d50\u679c\u70ba <code>true<\/code>\uff0c\u8868\u660e\u8eca\u724c\u865f\u78bc\u7b26\u5408\u898f\u5b9a\u3002<\/p>\n<p>\u7e3d\u7d50\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528 React.JS \u4f86\u6aa2\u67e5\u8eca\u724c\u865f\u78bc\u662f\u5426\u7b26\u5408\u898f\u5b9a\u3002\u6211\u5011\u53ef\u4ee5\u4f7f\u7528 React \u7d44\u4ef6\u4f86\u5275\u5efa\u4e00\u500b\u7528\u65bc\u6aa2\u67e5\u8eca\u724c\u865f\u78bc\u662f\u5426\u7b26\u5408\u898f\u5b9a\u7684\u529f\u80fd\uff0c\u4e26\u4f7f\u7528\u6b63\u5247\u8868\u9054\u5f0f\u4f86\u6aa2\u67e5\u8eca\u724c\u865f\u78bc\u662f\u5426\u7b26\u5408\u898f\u5b9a\u3002<\/p>\n<p><!--more--><\/p>\n<h2>\u7e3d\u7d50<\/h2>\n<p>\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5011\u4ecb\u7d39\u4e86\u5982\u4f55\u4f7f\u7528 React.JS \u4f86\u6aa2\u67e5\u8eca\u724c\u865f\u78bc\u662f\u5426\u7b26\u5408\u898f\u5b9a\u3002\u6211\u5011\u53ef\u4ee5\u4f7f\u7528 React \u7d44\u4ef6\u4f86\u5275\u5efa\u4e00\u500b\u7528\u65bc\u6aa2\u67e5\u8eca\u724c\u865f\u78bc\u662f\u5426\u7b26\u5408\u898f\u5b9a\u7684\u529f\u80fd\uff0c\u4e26\u4f7f\u7528\u6b63\u5247\u8868\u9054\u5f0f\u4f86\u6aa2\u67e5\u8eca\u724c\u865f\u78bc\u662f\u5426\u7b26\u5408\u898f\u5b9a\u3002\u901a\u904e\u4f7f\u7528 React.JS\uff0c\u6211\u5011\u53ef\u4ee5\u5feb\u901f\u69cb\u5efa\u51fa\u9ad8\u54c1\u8cea\u7684\u8eca\u724c\u865f\u78bc\u6aa2\u67e5\u529f\u80fd\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981\uff1a\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528React.JS\u4f86\u9a57\u8b49\u8eca\u724c\u865f\u78bc\u7684\u6709\u6548\u6027\uff0c\u4e26\u63d0\u4f9b\u4e00\u500b\u7c21\u55ae\u7684\u793a\u4f8b\u4f86\u89e3\u91cb\u5982\u4f55\u4f7f\u7528React.JS\u4f86\u5be6\u73fe\u8a72\u529f\u80fd\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[184,183],"tags":[182,181],"class_list":["post-5659","post","type-post","status-publish","format-standard","hentry","category-react","category-react-js","tag-react","tag-react-js"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1th","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5659","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/comments?post=5659"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5659\/revisions"}],"predecessor-version":[{"id":5660,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5659\/revisions\/5660"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=5659"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=5659"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=5659"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}