{"id":2182,"date":"2024-11-10T12:30:11","date_gmt":"2024-11-10T04:30:11","guid":{"rendered":"https:\/\/fwq.ai\/blog\/2182\/"},"modified":"2024-11-10T12:30:11","modified_gmt":"2024-11-10T04:30:11","slug":"%e4%b8%ba%e4%bb%80%e4%b9%88-javascript-%e5%ae%9a%e6%97%b6%e5%99%a8%e5%8f%a0%e5%8a%a0%e5%90%8e%e4%bc%9a%e5%8a%a0%e9%80%9f%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/2182\/","title":{"rendered":"\u4e3a\u4ec0\u4e48 JavaScript \u5b9a\u65f6\u5668\u53e0\u52a0\u540e\u4f1a\u52a0\u901f\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173068290398139.jpg\" class=\"aligncenter\" title=\"\u4e3a\u4ec0\u4e48 JavaScript \u5b9a\u65f6\u5668\u53e0\u52a0\u540e\u4f1a\u52a0\u901f\uff1f\u63d2\u56fe\" alt=\"\u4e3a\u4ec0\u4e48 JavaScript \u5b9a\u65f6\u5668\u53e0\u52a0\u540e\u4f1a\u52a0\u901f\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5b9a\u65f6\u5668\u53e0\u52a0\u5bfc\u81f4\u901f\u5ea6\u52a0\u5feb\u7684\u89e3\u6790<\/strong><\/p>\n<p>\u5728 javascript \u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u5e38\u5e38\u4f7f\u7528\u5b9a\u65f6\u5668\u6765\u6267\u884c\u5468\u671f\u6027\u4efb\u52a1\u3002\u800c\u6700\u8fd1\uff0c\u6709\u4eba\u9047\u5230\u4e86\u4e00\u4e2a\u5947\u602a\u7684\u95ee\u9898\uff0c\u5373\u5b9a\u65f6\u5668\u53e0\u52a0\u540e\u901f\u5ea6\u4f1a\u52a0\u5feb\u3002<\/p>\n<p>\u95ee\u9898\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>var timer = setInterval(function(){\n    \/\/...\n}, 10)\n\n$('li').hover(function() {\n    clearInterval(timer);\n},\nfunction() {\n    \/\/\u6211\u77e5\u9053\u8fd9\u8fb9\u662f\u56e0\u4e3a\u53c8\u91cd\u65b0\u521b\u5efa\u4e86\u4e00\u4e2atimer\u7684\u5b9a\u65f6\u5668\uff0c\u624d\u9020\u6210\u53e0\u52a0\u6548\u679c\n    \/\/\u4e3a\u4ec0\u4e48clearInterval(timer)\u6e05\u9664\u4e0d\u4e86\uff0c\u95ee\u4e86\u522b\u4eba\u662f\u56e0\u4e3a\u6e05\u9664\u7684\u662f\u7b2c\u4e00\u4e2atimer\n    \/\/\u4e3a\u4ec0\u4e48\uff1f\u91cd\u65b0\u5b9a\u4e49\u7684\u5b9a\u65f6\u5668\u4e5f\u53ebtimer\u4e86\uff0ctimer\u4e0d\u662f\u88ab\u91cd\u65b0\u8d4b\u503c\u4e86\uff0c\u4e3a\u4ec0\u4e48\u6e05\u9664\u4e0d\u4e86\n    \/\/\u8fd8\u6709\u4e00\u4e2a\u95ee\u9898\u4e3a\u4ec0\u4e48\u5b9a\u65f6\u5668\u53e0\u52a0\u4e86\uff0c\u901f\u5ea6\u4f1a\u52a0\u5feb\uff0c\u53ef\u4ee5\u8bf4\u5f97\u8be6\u7ec6\u70b9\uff1f\n\n    var timer = setInterval(function(){\n        \/\/...\n    }, 10)\n});<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u95ee\u9898\u89e3\u6790<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<ul>\n<li>\n<p><strong>clearinterval(timer) \u6e05\u9664\u7684\u662f\u7b2c\u4e00\u4e2a\u5b9a\u65f6\u5668<\/strong><\/p>\n<p>var timer = setinterval(&#8230;) \u51fd\u6570\u4f1a\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5b9a\u65f6\u5668\u5e76\u8fd4\u56de\u5176 id\u3002\u5f53\u4f7f\u7528 clearinterval(timer) \u65f6\uff0c\u5b83\u5c06\u6e05\u9664\u6b64 id \u5bf9\u5e94\u7684\u5b9a\u65f6\u5668\u3002\u800c\u5728\u4ee3\u7801\u4e2d\uff0c\u6bcf\u5f53\u9f20\u6807\u60ac\u505c\u5728 li \u5143\u7d20\u4e0a\u65f6\uff0c\u4f1a\u521b\u5efa\u4e86\u4e00\u4e2a\u65b0\u7684\u5b9a\u65f6\u5668\u5e76\u8986\u76d6\u4e86\u5148\u524d\u7684 var timer\u3002\u56e0\u6b64\uff0cclearinterval(timer) \u5b9e\u9645\u4e0a\u6e05\u9664\u7684\u662f\u7b2c\u4e00\u4e2a\u5b9a\u65f6\u5668\uff0c\u800c\u7b2c\u4e8c\u4e2a\u5b9a\u65f6\u5668\u4ecd\u7136\u5728\u8fd0\u884c\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u91cd\u65b0\u5b9a\u4e49\u7684\u5b9a\u65f6\u5668\u5bfc\u81f4 var timer \u6210\u4e3a\u5c40\u90e8\u53d8\u91cf<\/strong><\/p>\n<p>\u5728 javascript \u4e2d\uff0cvar \u58f0\u660e\u7684\u53d8\u91cf\u5177\u6709\u51fd\u6570\u3002\u5f53\u5728\u51fd\u6570\u5185\u4f7f\u7528 var \u58f0\u660e\u53d8\u91cf\u65f6\uff0c\u5b83\u5b9e\u9645\u4e0a\u521b\u5efa\u4e86\u4e00\u4e2a\u5c40\u90e8\u53d8\u91cf\uff0c\u800c\u4e0d\u662f\u8986\u76d6\u5168\u5c40\u53d8\u91cf\u3002\u56e0\u6b64\uff0c\u5f53\u5728\u9f20\u6807\u60ac\u505c\u4e8b\u4ef6\u5904\u7406\u7a0b\u5e8f\u4e2d\u91cd\u65b0\u5b9a\u4e49 timer \u65f6\uff0c\u5b83\u6210\u4e3a\u4e00\u4e2a\u5c40\u90e8\u53d8\u91cf\uff0c\u4e0e\u5168\u5c40\u53d8\u91cf timer \u4e0d\u540c\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u5b9a\u65f6\u5668\u53e0\u52a0\u5bfc\u81f4\u901f\u5ea6\u52a0\u5feb<\/strong><\/p>\n<p>\u5f53\u591a\u4e2a\u5b9a\u65f6\u5668\u540c\u65f6\u6267\u884c\u540c\u4e00\u4efb\u52a1\u65f6\uff0c\u53ef\u80fd\u4f1a\u51fa\u73b0\u901f\u5ea6\u52a0\u5feb\u7684\u73b0\u8c61\u3002\u8fd9\u662f\u56e0\u4e3a\u6bcf\u4e2a\u5b9a\u65f6\u5668\u90fd\u662f\u72ec\u7acb\u8fd0\u884c\u7684\uff0c\u5b83\u4eec\u90fd\u5728\u4e89\u593a cpu \u65f6\u95f4\u3002\u56e0\u6b64\uff0c\u540c\u65f6\u8fd0\u884c\u7684\u5b9a\u65f6\u5668\u8d8a\u591a\uff0ccpu \u53ef\u7528\u4e8e\u6267\u884c\u5176\u4ed6\u4efb\u52a1\u7684\u65f6\u95f4\u5c31\u8d8a\u5c11\uff0c\u4ece\u800c\u5bfc\u81f4\u6574\u4f53\u901f\u5ea6\u4e0b\u964d\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u4e3a\u4ec0\u4e48 JavaScript \u5b9a\u65f6\u5668\u53e0\u52a0\u540e\u4f1a\u52a0\u901f\uff1f\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>\u5b9a\u65f6\u5668\u53e0\u52a0\u5bfc\u81f4\u901f\u5ea6\u52a0\u5feb\u7684\u89e3\u6790 \u5728 javascript \u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u5e38\u5e38\u4f7f\u7528\u5b9a\u65f6\u5668\u6765\u6267\u884c\u5468\u671f\u6027\u4efb\u52a1\u3002\u800c\u6700\u8fd1\uff0c\u6709\u4eba\u9047\u5230\u4e86\u4e00\u4e2a\u5947\u602a\u7684\u95ee\u9898\uff0c\u5373\u5b9a\u65f6\u5668\u53e0\u52a0\u540e\u901f\u5ea6\u4f1a\u52a0\u5feb\u3002 \u95ee\u9898\u7684\u4ee3\u7801\u5982\u4e0b\uff1a var timer = setInterval(function(){ \/\/&#8230; }, 10) $(&#8216;li&#8217;).hover(function() { clearInterval(timer); }, function() { \/\/\u6211\u77e5\u9053\u8fd9\u8fb9\u662f\u56e0\u4e3a\u53c8\u91cd\u65b0\u521b\u5efa\u4e86\u4e00\u4e2atimer\u7684\u5b9a\u65f6\u5668\uff0c\u624d\u9020\u6210\u53e0\u52a0\u6548\u679c \/\/\u4e3a\u4ec0\u4e48clearInterval(timer)\u6e05\u9664\u4e0d\u4e86\uff0c\u95ee\u4e86\u522b\u4eba\u662f\u56e0\u4e3a\u6e05\u9664\u7684\u662f\u7b2c\u4e00\u4e2atimer \/\/\u4e3a\u4ec0\u4e48\uff1f\u91cd\u65b0\u5b9a\u4e49\u7684\u5b9a\u65f6\u5668\u4e5f\u53ebtimer\u4e86\uff0ctimer\u4e0d\u662f\u88ab\u91cd\u65b0\u8d4b\u503c\u4e86\uff0c\u4e3a\u4ec0\u4e48\u6e05\u9664\u4e0d\u4e86 \/\/\u8fd8\u6709\u4e00\u4e2a\u95ee\u9898\u4e3a\u4ec0\u4e48\u5b9a\u65f6\u5668\u53e0\u52a0\u4e86\uff0c\u901f\u5ea6\u4f1a\u52a0\u5feb\uff0c\u53ef\u4ee5\u8bf4\u5f97\u8be6\u7ec6\u70b9\uff1f var timer = setInterval(function(){ \/\/&#8230; }, 10) }); \u767b\u5f55\u540e\u590d\u5236 \u95ee\u9898\u89e3\u6790 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b clearinterval(timer) \u6e05\u9664\u7684\u662f\u7b2c\u4e00\u4e2a\u5b9a\u65f6\u5668 var timer = setinterval(&#8230;) \u51fd\u6570\u4f1a\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5b9a\u65f6\u5668\u5e76\u8fd4\u56de\u5176 id\u3002\u5f53\u4f7f\u7528 clearinterval(timer) \u65f6\uff0c\u5b83\u5c06\u6e05\u9664\u6b64 id \u5bf9\u5e94\u7684\u5b9a\u65f6\u5668\u3002\u800c\u5728\u4ee3\u7801\u4e2d\uff0c\u6bcf\u5f53\u9f20\u6807\u60ac\u505c\u5728 li \u5143\u7d20\u4e0a\u65f6\uff0c\u4f1a\u521b\u5efa\u4e86\u4e00\u4e2a\u65b0\u7684\u5b9a\u65f6\u5668\u5e76\u8986\u76d6\u4e86\u5148\u524d\u7684 var timer\u3002\u56e0\u6b64\uff0cclearinterval(timer) \u5b9e\u9645\u4e0a\u6e05\u9664\u7684\u662f\u7b2c\u4e00\u4e2a\u5b9a\u65f6\u5668\uff0c\u800c\u7b2c\u4e8c\u4e2a\u5b9a\u65f6\u5668\u4ecd\u7136\u5728\u8fd0\u884c\u3002 \u91cd\u65b0\u5b9a\u4e49\u7684\u5b9a\u65f6\u5668\u5bfc\u81f4 var timer \u6210\u4e3a\u5c40\u90e8\u53d8\u91cf \u5728 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-2182","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2182","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=2182"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2182\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=2182"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=2182"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=2182"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}