[HTML/JS]模拟加锁防止重复点击

/ 47,863评论 / 169670阅读 / 0点赞

由于用户的网络环境等各种原因,防止按钮重复点击,表单重复提交等都是减少bug发生,降低服务器压力等相当有效的方法。下面来聊聊通过模拟我们在操作系统里类似加锁的思想来防止重复点击。

目录

思路


示例

<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>

结语

  1. DominicHOr说道:

    mexican drugstore online: mexico drug stores pharmacies – medicine in mexico pharmacies

  2. Waynetar说道:

    mexican online pharmacies prescription drugs: п»їbest mexican online pharmacies – pharmacies in mexico that ship to usa

  3. DominicHOr说道:

    buying from online mexican pharmacy: medication from mexico pharmacy – mexican pharmaceuticals online

  4. Uyholf说道:

    purchase terazosin for sale – generic tamsulosin 0.4mg priligy 90mg canada

  5. Lfbhrv说道:

    buy speman generic – order finasteride sale finasteride online order

  6. DominicHOr说道:

    buying prescription drugs in mexico online: buying from online mexican pharmacy – best online pharmacies in mexico

  7. NelsonSaIlk说道:

    mexican mail order pharmacies: mexican pharmaceuticals online – buying prescription drugs in mexico

  8. Waynetar说道:

    reputable mexican pharmacies online: reputable mexican pharmacies online – mexico drug stores pharmacies

  9. DominicHOr说道:

    mexico drug stores pharmacies: mexican drugstore online – best online pharmacies in mexico

  10. NelsonSaIlk说道:

    medication from mexico pharmacy: buying prescription drugs in mexico – buying prescription drugs in mexico

  11. Arnoldscava说道:

    mexico pharmacy buying prescription drugs in mexico online mexican online pharmacies prescription drugs

  12. NelsonSaIlk说道:

    reputable mexican pharmacies online: reputable mexican pharmacies online – buying from online mexican pharmacy

  13. Arnoldscava说道:

    mexican online pharmacies prescription drugs mexico pharmacies prescription drugs mexican online pharmacies prescription drugs

  14. NelsonSaIlk说道:

    mexico pharmacies prescription drugs: buying prescription drugs in mexico – reputable mexican pharmacies online

  15. Waynetar说道:

    mexico drug stores pharmacies: mexican mail order pharmacies – reputable mexican pharmacies online

  16. DominicHOr说道:

    mexico pharmacies prescription drugs: mexico drug stores pharmacies – mexico drug stores pharmacies

  17. Lazrrvy说道:

    Здравствуйте!
    Приобрести диплом университета.
    lastdemo.primepix.ru/club/user/88/blog/8745

  18. NelsonSaIlk说道:

    mexican online pharmacies prescription drugs: mexico drug stores pharmacies – mexican online pharmacies prescription drugs

  19. Arnoldscava说道:

    purple pharmacy mexico price list mexican rx online mexican border pharmacies shipping to usa

  20. Diplomi_wsol说道:

    Добрый день!
    Заказать документ о получении высшего образования можно у нас в Москве.
    diploms-x.com/kupit-diplom-kandidata-nauk

  21. Trefmkw说道:

    Привет!
    Сколько стоит диплом высшего и среднего образования и как его получить?
    theplaygamepicks.com/диплом-техникума-где-и-как-купить
    Рады оказать помощь!.

  22. Diplomi_lhol说道:

    Привет!
    Заказать документ университета можно в нашей компании.
    asxdiplomik.com/kupit-diplom-chelyabinsk

  23. Trefgmu说道:

    Привет!
    Официальная покупка диплома вуза с упрощенной программой обучения
    hi-fi-forum.net/profile/957272
    Рады помочь!.

  24. Lazrjjx说道:

    Добрый день!
    Мы готовы предложить дипломы любых профессий по приятным тарифам.
    asromafansclub.com/read-blog/5917_nadezhnyj-magazin-s-obshirnym-assortimentom-dokumentov

  25. Waynetar说道:

    mexico drug stores pharmacies: medication from mexico pharmacy – purple pharmacy mexico price list

  26. Arnoldscava说道:

    mexican pharmaceuticals online mexican rx online best online pharmacies in mexico

  27. DominicHOr说道:

    mexico pharmacies prescription drugs: buying prescription drugs in mexico – buying from online mexican pharmacy

  28. Waynetar说道:

    medication from mexico pharmacy: mexican pharmaceuticals online – best online pharmacies in mexico

  29. DominicHOr说道:

    mexican mail order pharmacies: buying prescription drugs in mexico – medication from mexico pharmacy

  30. Waynetar说道:

    mexico drug stores pharmacies: buying prescription drugs in mexico online – pharmacies in mexico that ship to usa

  31. DominicHOr说道:

    mexican pharmaceuticals online: pharmacies in mexico that ship to usa – п»їbest mexican online pharmacies

  32. NelsonSaIlk说道:

    п»їbest mexican online pharmacies: mexican border pharmacies shipping to usa – buying prescription drugs in mexico

  33. Waynetar说道:

    pharmacies in mexico that ship to usa: pharmacies in mexico that ship to usa – п»їbest mexican online pharmacies

  34. DominicHOr说道:

    п»їbest mexican online pharmacies: mexican pharmaceuticals online – mexican pharmaceuticals online

  35. NelsonSaIlk说道:

    mexican mail order pharmacies: п»їbest mexican online pharmacies – mexican mail order pharmacies

  36. Arnoldscava说道:

    mexican border pharmacies shipping to usa buying prescription drugs in mexico online mexico pharmacies prescription drugs

  37. Arnoldscava说道:

    medication from mexico pharmacy buying from online mexican pharmacy buying from online mexican pharmacy

  38. NelsonSaIlk说道:

    reputable mexican pharmacies online: mexican pharmaceuticals online – mexican online pharmacies prescription drugs

  39. Arnoldscava说道:

    purple pharmacy mexico price list buying from online mexican pharmacy mexican rx online

  40. NelsonSaIlk说道:

    pharmacies in mexico that ship to usa: mexico pharmacies prescription drugs – buying prescription drugs in mexico online

  41. DominicHOr说道:

    mexico pharmacies prescription drugs: medicine in mexico pharmacies – medicine in mexico pharmacies

  42. RichardAftem说道:

    [url=https://rentyachtsincyprus.com/en]Charter a yacht and experience the ultimate in luxury and convenience for your next special occasion or private vacation in Cyprus. Our highly trained crew is dedicated to ensuring your safety and wellbeing while providing exceptional service that caters to your every need. With our yachts maintained to the highest standards, you can relax and enjoy your trouble-free journey in style and comfort. Let us help you create unforgettable memories on the crystal-clear waters of your dream destination in Cyprus.[/url]

    [url=https://rentyachtsincyprus.com/]For lovers of outdoor activities and sunbathing by the pool, renting a yacht is the best solution, because while sunbathing in the bow of a yacht, you can simultaneously explore the many marine attractions located along the entire coast of Cyprus.[/url]

    [url=https://rentyachtsincyprus.com/]Extraordinarily beautiful sunrises and mysterious sunsets, vivid emotions from bewitching landscapes, exciting trails along the coastline of the island and lots of excitement from a boat trip.[/url]

    [url=https://rentyachtsincyprus.com/]Our company “Rent Yachts in Cyprus” provides yacht rental services in Cyprus. With our extensive fleet of yachts, we offer a variety of options for every taste and budget. Our team of experienced professionals is dedicated to providing exceptional service and ensuring that our customers have an unforgettable experience on the beautiful waters of Cyprus. Book your yacht rental with us and discover the stunning coastline of Cyprus in style and comfort.[/url]

  43. Uazralz说道:

    Привет!
    Приобрести диплом любого университета.
    jagplay.ekafe.ru/viewtopic.php?f=22&t=4149

  44. Uazrtbg说道:

    Привет!
    Заказать диплом ВУЗа.
    entrastart.com//read-blog/46

  45. NelsonSaIlk说道:

    mexican online pharmacies prescription drugs: pharmacies in mexico that ship to usa – п»їbest mexican online pharmacies

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注