由于用户的网络环境等各种原因,防止按钮重复点击,表单重复提交等都是减少bug发生,降低服务器压力等相当有效的方法。下面来聊聊通过模拟我们在操作系统里类似加锁的思想来防止重复点击。
目录
思路
- 声明一个锁(布尔值),用来标识按钮,变量是否被锁上
- 当按钮按下后,把布尔值设置为false,即标记为已锁上
- 设置一个延时函数setTimeout(),等待一段时间后再把这个锁归还,设置布尔值为true
- 显然我们的按钮点击事件一开始就应该判断锁是否被锁上,是则直接结束。否则才能正常执行
示例
- HTML / JS
<div style="width:100%;display:flex;justify-content: center;background:#66ccff;border-radius:10px;border 1px solid #66ccff;">
<button onclick="btn_click()" style="border-radius:10px;">
点死我
</button>
</div>
<script>
//锁变量
let lock = true;
//按钮点击执行函数
function btn_click() {
if(lock == false) {
return;
}
//加锁
lock = false;
//执行按钮点击本应执行的事情
alert("点了一下我捏");
//限制间隔5000毫秒(即5秒)只能执行一次
setTimeout(function(){
//解锁
lock = true;
},5000);
}
</script>
- 效果(每隔5秒只会执行一次按钮点击应该执行的事情):
结语
- 本文的例子思路和实现都是相当简单的,但确是很实用的方法。
- 另外,从这个思路出发,还能解决一些类似的问题,比如:
- 音乐进度条的拖动。由于拖动的报告率太高,导致拖动过程界面卡顿,音乐的播放也很卡顿,那就可以用这个思路,每一段时间内只对应响应一次。
- 降低输入框的响应。
- 后续我们再聊聊上面这些例子的解决方法实现。他们本质都是这个模拟加锁的思路,但可能有些需要一些细节上不同的处理。
canadian pharmacy synthroid
[url=https://medicinesaf.online/]online pharmacy 365 pills[/url]
foreign pharmacy no prescription cheapest pharmacy for prescriptions online pharmacy no prescription
canadian pharmacy no prescription: canada drugs coupon code – canadian pharmacy discount coupon
buy cheap synthroid
azithromycin
canadian pharmacy no prescription: foreign pharmacy no prescription – no prescription pharmacy paypal
maple leaf pharmacy in canada
synthroid 0.5 mg
buy valtrex without prescription
Within the continuously evolving arena of SEO, devices and strategies that might effectively enhance a website’s internet visibility are in persistent request. Introduce XRumer, a modern software built to power up link-building drives. With the potential to post on message boards, weblogs, guestbooks, and other platforms automatically, XRumer revolutionizes the way digital marketers tackle off-page SEO. This potent tool circumvents usual online barriers like CAPTCHAs, guaranteeing an uninterrupted and productive backlink production process. A properly executed XRumer SEO run might substantially raise a site’s search engine rankings, driving organic traffic and enhancing online appearance.
Still, while the potential of XRumer is incontestable, its use demands a planned and prudent method. Similar to all SEO instruments, the consequences are merely as superb as the method after them. Too much reliance or misuse can lead to unwanted results, including penalties from search engines for forced link building. Hence, when beginning on an XRumer SEO run, it’s vital to emphasize excellence over quantity, focusing on pertinent and high-authority sites that conform with the brand’s principles. In the grip of a talented SEO specialist, XRumer becomes a powerful asset, bridging the gap between a brand and its internet possibility.
Telgrm: @xrumers
https://XRumer.cc/
Skype: XRumer.pro
tadalafil buy online uk
buy desloratadine 5mg sale – buy generic triamcinolone brand ventolin 2mg
valtrex canadian pharmacy
I highly advise steer clear of this platform. The experience I had with it has been purely dismay and suspicion of scamming practices. Exercise extreme caution, or better yet, seek out an honest service to meet your needs.
SEO services are the unheralded protagonists of the digital age, supplying enterprises with the resources and tactics to radiate brightly in the vast universe of internet information. By dipping into the capability of productive keyword focusing, quality inbound link acquisition, and material enhancement, these services ensure that a site is not merely visible, but stands out as a beacon of applicability and command in its niche. The charm of SEO lies in its capacity to naturally elevate a company’s presence, pulling in viewers truly intrigued in what’s on presentation, and forming valuable interactions that guide to persistent connections.
In a globe where digital dominance often commands victory, having a customized SEO plan is similar to having a master answer to the online urban. All tweak and change made by SEO specialists isn’t only about placating algorithms, but more importantly, about comprehending and catering to human actions and requirements. The conclusive aim? To harmoniously unite a brand with its perfect audience, promoting growth, confidence, and prolonged success. In this endeavor, SEO methods prove to be not only beneficial, but indispensable.
Telegram: @exrumer
https://XRumer.cc/
Skype: XRumer.pro
http://medicationnoprescription.pro/# canada pharmacy without prescription
SEO services are the unsung heroes of the online era, providing enterprises with the resources and strategies to radiate brightly in the vast realm of online material. By dipping into the possibility of efficient search term focusing, prime inbound link acquisition, and content improvement, these methods ensure that a website is not merely noticeable, but distinguishes itself as a signal of relevancy and power in its niche. The charm of SEO resides in its capability to spontaneously elevate a brand’s presence, drawing in viewers truly engaged in what is on offer, and creating meaningful engagements that lead to persistent relationships.
In a globe where online standing often dictates success, having a customized SEO approach is similar to having a master solution to the online city. All tweak and alteration made by SEO specialists isn’t merely about placating calculations, but more significantly, about understanding and catering to person behaviors and needs. The end goal? To peacefully unite a brand with its ideal audience, promoting expansion, confidence, and extended achievement. In this endeavor, SEO methods show to be not just advantageous, but crucial.
Telgrm: @xrumers
https://XRumer.cc/
Skype: XRumer.pro
online pharmacy delivery
I urge you steer clear of this site. My personal experience with it has been nothing but disappointment and suspicion of fraudulent activities. Be extremely cautious, or better yet, find a more reputable platform for your needs.
how to get ed meds online top rated ed pills boner pills online
cost of prednisone 5mg tablets
I strongly recommend stay away from this platform. My own encounter with it was only frustration as well as concerns regarding scamming practices. Exercise extreme caution, or even better, seek out an honest service for your needs.
ed drugs online: pills for erectile dysfunction online – order ed meds online
[url=http://prednisoneo.com/]buy prednisone without a prescription[/url]
canadian mail order prescriptions canadian and international prescription service pharmacies without prescriptions
ed online prescription: ed treatments online – online ed medicine
ed online prescription: cheapest ed treatment – what is the cheapest ed medication
lisinopril drug
https://medicationnoprescription.pro/# no prescription on line pharmacies
Search Engine Optimization solutions are the overlooked heroes of the internet era, offering enterprises with the tools and approaches to glow vibrantly in the vast world of online material. By delving into the potential of productive search term targeting, prime inbound link procurement, and content optimization, these solutions assure that a site is not merely apparent, but distinguishes itself as a signal of applicability and power in its sector. The beauty of SEO is in its capability to organically lift a brand’s presence, drawing in audiences truly intrigued in what’s on display, and creating meaningful interactions that lead to persistent ties.
In a world where internet dominance often determines victory, having a tailored SEO plan is akin to having a chief key to the digital metropolis. All adjustment and change made by SEO professionals isn’t just about satisfying calculations, but more significantly, about understanding and catering to individual actions and necessities. The final goal? To peacefully merge a business with its perfect audience, fostering development, confidence, and prolonged victory. In this attempt, SEO services show to be not just advantageous, but essential.
Telgrm: @exrumer
https://XRumer.cc/
Skype: XRumer.pro
buy synthroid 112 mcg
prescription canada: purchasing prescription drugs online – mexico prescription drugs online
clarinex 5mg without prescription – purchase aristocort online buy albuterol generic
online ed pills ed meds by mail cheap erectile dysfunction pills
lisinopril for sale
offshore pharmacy no prescription
amiloride vs spironolactone
no prescription required pharmacy: no prescription required pharmacy – canada online pharmacy no prescription
https://onlinepharmacyworld.shop/# pharmacy no prescription required
cheap erectile dysfunction pills: order ed pills online – how to get ed pills
http://medicationnoprescription.pro/# buy pain meds online without prescription
https://medicationnoprescription.pro/# canada pharmacy without prescription
https://onlinepharmacyworld.shop/# cheap pharmacy no prescription
https://onlinepharmacyworld.shop/# no prescription needed pharmacy
doubling synthroid
ed medicines online low cost ed meds online buy ed meds online
http://medicationnoprescription.pro/# can i buy prescription drugs in canada
synthroid 135 mcg
zithromax 250 mg canada