{"id":159844,"date":"2024-05-08T13:18:12","date_gmt":"2024-05-08T05:18:12","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/159844.html"},"modified":"2024-05-08T13:18:16","modified_gmt":"2024-05-08T05:18:16","slug":"%e5%89%8d%e7%ab%af-javascript-%e5%87%bd%e6%95%b0%e8%8a%82%e6%b5%81%e5%92%8c%e9%98%b2%e6%8a%96%e7%9a%84%e5%ba%94%e7%94%a8%e5%9c%ba%e6%99%af%e6%9c%89%e5%93%aa%e4%ba%9b","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/159844.html","title":{"rendered":"\u524d\u7aef javascript \u51fd\u6570\u8282\u6d41\u548c\u9632\u6296\u7684\u5e94\u7528\u573a\u666f\u6709\u54ea\u4e9b"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/26222422\/80dc43f4-7196-459e-a85c-34672718fa29.webp\" alt=\"\u524d\u7aef javascript \u51fd\u6570\u8282\u6d41\u548c\u9632\u6296\u7684\u5e94\u7528\u573a\u666f\u6709\u54ea\u4e9b\" \/><\/p>\n<p><p>\u5728\u524d\u7aef\u5f00\u53d1\u4e2d\uff0c<strong>\u51fd\u6570\u8282\u6d41\uff08Throttling\uff09\u548c\u51fd\u6570\u9632\u6296\uff08Debouncing\uff09<\/strong> \u90fd\u662f\u4f18\u5316\u9ad8\u9891\u4e8b\u4ef6\u89e6\u53d1\u65f6\u6027\u80fd\u7684\u6709\u6548\u6280\u672f\u3002\u51fd\u6570\u8282\u6d41\u901a\u8fc7\u89c4\u5b9a\u5728\u7279\u5b9a\u7684\u65f6\u95f4\u5185\u53ea\u80fd\u6267\u884c\u4e00\u6b21\u51fd\u6570\u6765\u51cf\u5c11\u51fd\u6570\u7684\u8c03\u7528\u6b21\u6570\uff0c\u800c\u51fd\u6570\u9632\u6296\u5219\u662f\u5728\u4e8b\u4ef6\u89e6\u53d1\u4e00\u6bb5\u65f6\u95f4\u540e\u624d\u6267\u884c\u51fd\u6570\uff0c\u5982\u679c\u5728\u8fd9\u6bb5\u65f6\u95f4\u5185\u4e8b\u4ef6\u518d\u6b21\u88ab\u89e6\u53d1\uff0c\u5219\u91cd\u65b0\u8ba1\u65f6\u3002\u5b83\u4eec\u7684\u5e94\u7528\u573a\u666f\u5305\u62ec\u4f46\u4e0d\u9650\u4e8e\uff1a<strong>\u7a97\u53e3\u5c3a\u5bf8\u53d8\u5316\uff08resize\uff09\u3001\u9875\u9762\u6eda\u52a8\uff08scroll\uff09\u3001\u8868\u5355\u9a8c\u8bc1\uff08input\uff09\u548c\u81ea\u52a8\u5b8c\u6210\uff08autocomplete\uff09<\/strong>\u3002 \u5bf9\u4e8e\u51fd\u6570\u8282\u6d41\u6765\u8bf4\uff0c\u6700\u5178\u578b\u7684\u5e94\u7528\u573a\u666f\u4e4b\u4e00\u662f\u9875\u9762\u6eda\u52a8\u4e8b\u4ef6\uff08scroll\uff09\uff0c\u56e0\u4e3a\u6eda\u52a8\u4e8b\u4ef6\u5728\u77ed\u65f6\u95f4\u5185\u53ef\u4ee5\u88ab\u89e6\u53d1\u975e\u5e38\u591a\u6b21\uff0c\u5982\u679c\u5728\u6eda\u52a8\u5904\u7406\u51fd\u6570\u4e2d\u6267\u884c\u590d\u6742\u903b\u8f91\u6216\u8005DOM\u64cd\u4f5c\uff0c\u53ef\u80fd\u4f1a\u9020\u6210\u4e25\u91cd\u7684\u6027\u80fd\u95ee\u9898\u3002\u901a\u8fc7\u8282\u6d41\uff0c\u6211\u4eec\u53ef\u4ee5\u786e\u4fdd\u5373\u4f7fscroll\u4e8b\u4ef6\u89e6\u53d1\u5f97\u5f88\u9891\u7e41\uff0c\u5904\u7406\u51fd\u6570\u4e5f\u53ea\u5728\u56fa\u5b9a\u7684\u65f6\u95f4\u95f4\u9694\u5185\u88ab\u8c03\u7528\uff0c\u4ece\u800c\u4f18\u5316\u6027\u80fd\u5e76\u907f\u514d\u9875\u9762\u5361\u987f\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u51fd\u6570\u8282\u6d41\u7684\u5e94\u7528\u573a\u666f<\/h3>\n<\/p>\n<p><h4>\u7a97\u53e3\u5c3a\u5bf8\u53d8\u5316\uff08Resize\uff09<\/h4>\n<\/p>\n<p><p>\u7a97\u53e3\u5c3a\u5bf8\u53d8\u5316\u662f\u7528\u6237\u5728\u8c03\u6574\u6d4f\u89c8\u5668\u7a97\u53e3\u5927\u5c0f\u65f6\u9891\u7e41\u53d1\u751f\u7684\u4e8b\u4ef6\u3002\u6ca1\u6709\u8282\u6d41\u63a7\u5236\u7684\u60c5\u51b5\u4e0b\uff0cresize\u4e8b\u4ef6\u53ef\u4ee5\u5728\u5f88\u77ed\u7684\u65f6\u95f4\u5185\u89e6\u53d1\u6570\u5341\u751a\u81f3\u6570\u767e\u6b21\u3002\u5f53\u6211\u4eec\u9700\u8981\u6839\u636e\u7a97\u53e3\u5927\u5c0f\u8c03\u6574\u9875\u9762\u5e03\u5c40\u65f6\uff0c\u8fd9\u79cd\u9891\u7e41\u7684\u89e6\u53d1\u4f1a\u5bfc\u81f4\u9875\u9762\u6027\u80fd\u4e0b\u964d\u3002\u4f7f\u7528\u8282\u6d41\u53ef\u4ee5\u964d\u4f4e\u4e8b\u4ef6\u5904\u7406\u51fd\u6570\u7684\u8c03\u7528\u9891\u7387\uff0c\u4f7f\u9875\u9762\u54cd\u5e94\u66f4\u4e3a\u6d41\u7545\u3002<\/p>\n<\/p>\n<p><h4>\u9875\u9762\u6eda\u52a8\uff08Scroll\uff09<\/h4>\n<\/p>\n<p><p>\u5728\u5b9e\u73b0\u65e0\u9650\u6eda\u52a8\u6216\u8005\u6eda\u52a8\u76d1\u542c\u7684\u529f\u80fd\u65f6\uff0cscroll\u4e8b\u4ef6\u540c\u6837\u4f1a\u975e\u5e38\u9891\u7e41\u5730\u89e6\u53d1\u3002\u5982\u679c\u6bcf\u6b21\u6eda\u52a8\u90fd\u8fdb\u884c\u5927\u91cf\u8ba1\u7b97\u6216\u8005\u66f4\u65b0DOM\uff0c\u5c06\u9020\u6210\u4e25\u91cd\u7684\u6027\u80fd\u95ee\u9898\u3002\u8282\u6d41\u6280\u672f\u53ef\u4ee5\u4fdd\u8bc1\u5728\u56fa\u5b9a\u7684\u65f6\u95f4\u95f4\u9694\u5185\u53ea\u5904\u7406\u4e00\u6b21\u6eda\u52a8\u4e8b\u4ef6\uff0c\u63d0\u9ad8\u9875\u9762\u6eda\u52a8\u7684\u6027\u80fd\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u51fd\u6570\u9632\u6296\u7684\u5e94\u7528\u573a\u666f<\/h3>\n<\/p>\n<p><h4>\u8868\u5355\u9a8c\u8bc1\uff08Input\uff09<\/h4>\n<\/p>\n<p><p>\u5f53\u7528\u6237\u5728\u8f93\u5165\u6846\u4e2d\u8f93\u5165\u5185\u5bb9\u8fdb\u884c\u8868\u5355\u9a8c\u8bc1\u65f6\uff0c\u5982\u679c\u5bf9\u6bcf\u4e00\u4e2a\u952e\u76d8\u4e8b\u4ef6\u90fd\u8fdb\u884c\u5904\u7406\uff0c\u5c06\u5e26\u6765\u4e0d\u5fc5\u8981\u7684\u670d\u52a1\u5668\u8bf7\u6c42\u6216\u9875\u9762\u6e32\u67d3\u3002\u901a\u8fc7\u9632\u6296\u6280\u672f\uff0c\u53ef\u4ee5\u5728\u7528\u6237\u505c\u6b62\u8f93\u5165\u4e00\u6bb5\u65f6\u95f4\u540e\u518d\u6267\u884c\u9a8c\u8bc1\u903b\u8f91\uff0c\u65e2\u53ef\u4ee5\u51cf\u5c11\u4e0d\u5fc5\u8981\u7684\u9a8c\u8bc1\u6b21\u6570\uff0c\u4e5f\u80fd\u63d0\u5347\u7528\u6237\u4f53\u9a8c\uff0c\u907f\u514d\u5728\u7528\u6237\u8f93\u5165\u8fc7\u7a0b\u4e2d\u9891\u7e41\u5730\u7ed9\u7528\u6237\u53cd\u9988\u3002<\/p>\n<\/p>\n<p><h4>\u81ea\u52a8\u5b8c\u6210\uff08Autocomplete\uff09<\/h4>\n<\/p>\n<p><p>\u5728\u641c\u7d22\u680f\u6216\u67d0\u4e9b\u9700\u8981\u81ea\u52a8\u5b8c\u6210\u7684\u8f93\u5165\u6846\u4e2d\uff0c\u5229\u7528\u9632\u6296\u6280\u672f\u53ef\u4ee5\u5728\u7528\u6237\u505c\u6b62\u8f93\u5165\u4e00\u5b9a\u65f6\u95f4\u540e\u624d\u89e6\u53d1\u641c\u7d22\u8bf7\u6c42\uff0c\u907f\u514d\u4e86\u6bcf\u6b21\u7528\u6237\u8f93\u5165\u65f6\u90fd\u53d1\u9001\u8bf7\u6c42\u7684\u60c5\u51b5\u3002\u8fd9\u6837\u4e0d\u4ec5\u51cf\u5c11\u4e86\u670d\u52a1\u5668\u538b\u529b\uff0c\u4e5f\u4f7f\u7528\u6237\u4f53\u9a8c\u66f4\u4e3a\u6d41\u7545\u3002<\/p>\n<\/p>\n<p><p>\u5e94\u7528\u51fd\u6570\u8282\u6d41\u548c\u9632\u6296\u7684\u6280\u672f\uff0c\u53ef\u4ee5\u5927\u5927\u63d0\u5347\u524d\u7aef\u6027\u80fd\u548c\u7528\u6237\u4f53\u9a8c\u3002\u5f00\u53d1\u8005\u9700\u8981\u6839\u636e\u4e0d\u540c\u573a\u666f\u9009\u62e9\u5408\u9002\u7684\u6280\u672f\u6765\u89e3\u51b3\u95ee\u9898\uff1a\u8282\u6d41\u5bf9\u4e8e\u9700\u8981\u4ee5\u4e00\u5b9a\u9891\u7387\u66f4\u65b0\u6216\u8005\u83b7\u53d6\u6570\u636e\u7684\u60c5\u51b5\u975e\u5e38\u6709\u6548\uff0c\u5982\u6eda\u52a8\u52a0\u8f7d\u3001\u5c3a\u5bf8\u53d8\u5316\u7b49\uff1b\u800c\u9632\u6296\u66f4\u9002\u7528\u4e8e\u90a3\u4e9b\u4e0d\u9700\u8981\u7acb\u5373\u54cd\u5e94\u7528\u6237\u64cd\u4f5c\uff0c\u4e14\u6709\u4e00\u5b9a\u5ef6\u8fdf\u624d\u9700\u8fdb\u884c\u5904\u7406\u7684\u573a\u666f\uff0c\u5982\u8f93\u5165\u6846\u9a8c\u8bc1\u3001\u641c\u7d22\u6846\u81ea\u52a8\u5b8c\u6210\u7b49\u3002\u901a\u8fc7\u9002\u5f53\u5e94\u7528\u8fd9\u4e24\u79cd\u6280\u672f\uff0c\u53ef\u4ee5\u4fdd\u6301\u5e94\u7528\u7684\u54cd\u5e94\u6027\u548c\u6d41\u7545\u5ea6\uff0c\u540c\u65f6\u51cf\u8f7b\u670d\u52a1\u5668\u8d1f\u62c5\uff0c\u63d0\u5347\u6574\u4f53\u7684\u524d\u7aef\u6027\u80fd\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p><strong>1. \u4f55\u65f6\u5e94\u8be5\u4f7f\u7528\u51fd\u6570\u8282\u6d41\u548c\u9632\u6296\uff1f<\/strong><\/p>\n<ul>\n<li>\u5f53\u7528\u6237\u9891\u7e41\u7684\u89e6\u53d1\u4e00\u4e2a\u4e8b\u4ef6\u65f6\uff0c\u4f8b\u5982\u6eda\u52a8\u9875\u9762\u3001\u62d6\u62fd\u64cd\u4f5c\u6216\u8005\u8fde\u7eed\u7684\u70b9\u51fb\u6309\u94ae\uff0c\u8fd9\u65f6\u5c31\u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u51fd\u6570\u8282\u6d41\u548c\u9632\u6296\u6765\u4f18\u5316\u6027\u80fd\u3002<\/li>\n<li>\u5f53\u9700\u8981\u9650\u5236\u67d0\u4e9b\u9ad8\u9891\u89e6\u53d1\u4e8b\u4ef6\u7684\u6267\u884c\u9891\u7387\uff0c\u4ee5\u907f\u514d\u6d4f\u89c8\u5668\u7684\u6027\u80fd\u95ee\u9898\u548c\u5361\u987f\u73b0\u8c61\u65f6\uff0c\u4e5f\u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u51fd\u6570\u8282\u6d41\u548c\u9632\u6296\u3002<\/li>\n<\/ul>\n<p><strong>2. \u51fd\u6570\u8282\u6d41\u7684\u5e94\u7528\u573a\u666f<\/strong><\/p>\n<ul>\n<li>\u5728\u5b9e\u65f6\u641c\u7d22\u529f\u80fd\u4e2d\uff0c\u5f53\u7528\u6237\u8f93\u5165\u641c\u7d22\u5173\u952e\u5b57\u65f6\uff0c\u53ef\u4ee5\u5229\u7528\u51fd\u6570\u8282\u6d41\u6765\u63a7\u5236\u641c\u7d22\u8bf7\u6c42\u7684\u9891\u7387\uff0c\u907f\u514d\u9891\u7e41\u53d1\u9001\u8bf7\u6c42\u3002<\/li>\n<li>\u5f53\u7a97\u53e3\u5927\u5c0f\u6539\u53d8\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u51fd\u6570\u8282\u6d41\u6765\u63a7\u5236\u89e6\u53d1\u4e8b\u4ef6\u7684\u9891\u7387\uff0c\u907f\u514d\u8fc7\u591a\u7684\u8ba1\u7b97\u548c\u6837\u5f0f\u6e32\u67d3\u3002<\/li>\n<li>\u5728\u65e0\u9650\u6eda\u52a8\u52a0\u8f7d\u66f4\u591a\u5185\u5bb9\u7684\u9875\u9762\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u51fd\u6570\u8282\u6d41\u6765\u63a7\u5236\u6eda\u52a8\u4e8b\u4ef6\u7684\u89e6\u53d1\u9891\u7387\uff0c\u4ee5\u51cf\u5c11\u8bf7\u6c42\u6b21\u6570\u548c\u63d0\u5347\u6027\u80fd\u3002<\/li>\n<\/ul>\n<p><strong>3. \u51fd\u6570\u9632\u6296\u7684\u5e94\u7528\u573a\u666f<\/strong><\/p>\n<ul>\n<li>\u5728\u7528\u6237\u8f93\u5165\u6846\u4e2d\u8fdb\u884c\u5b9e\u65f6\u641c\u7d22\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u51fd\u6570\u9632\u6296\u6765\u5ef6\u8fdf\u53d1\u9001\u641c\u7d22\u8bf7\u6c42\uff0c\u4ee5\u907f\u514d\u7528\u6237\u8f93\u5165\u8fc7\u5feb\u5bfc\u81f4\u8bf7\u6c42\u9891\u7e41\u3002<\/li>\n<li>\u5f53\u7528\u6237\u8fde\u7eed\u70b9\u51fb\u67d0\u4e2a\u6309\u94ae\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u51fd\u6570\u9632\u6296\u6765\u5408\u5e76\u591a\u6b21\u70b9\u51fb\u4e8b\u4ef6\uff0c\u53ea\u6267\u884c\u6700\u540e\u4e00\u6b21\u70b9\u51fb\u65f6\u7684\u64cd\u4f5c\u3002<\/li>\n<li>\u5728\u7a97\u53e3\u5927\u5c0f\u6539\u53d8\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u51fd\u6570\u9632\u6296\u6765\u5ef6\u8fdf\u89e6\u53d1\u4e8b\u4ef6\uff0c\u4ee5\u907f\u514d\u8fc7\u591a\u7684\u8ba1\u7b97\u548c\u6837\u5f0f\u6e32\u67d3\u7684\u64cd\u4f5c\u3002<\/li>\n<\/ul>\n<p>\u8bf7\u6ce8\u610f\u907f\u514d\u5728FAQs\u4e2d\u51fa\u73b0\u9996\u5148\u3001\u5176\u6b21\u3001\u7136\u540e\u3001\u6700\u7ec8\u3001\u6700\u540e\u7b49\u5173\u952e\u8bcd\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728\u524d\u7aef\u5f00\u53d1\u4e2d\uff0c\u51fd\u6570\u8282\u6d41\uff08Throttling\uff09\u548c\u51fd\u6570\u9632\u6296\uff08Debouncing\uff09 \u90fd\u662f\u4f18\u5316\u9ad8\u9891\u4e8b\u4ef6\u89e6\u53d1\u65f6\u6027\u80fd\u7684 [&hellip;]","protected":false},"author":3,"featured_media":159847,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/159844"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=159844"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/159844\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/159847"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=159844"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=159844"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=159844"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}