1. //验证码
    2. $(".obtainCode").click(function () {
    3. var countdown = 60; //倒计时秒数
    4. var btnSendCode = $(this); // 当前点击的元素
    5. setTime(btnSendCode, countdown);
    6. });
    7. /**
    8. * @param {*} btnSendCode 当前点击元素
    9. * @param {*} countdown 倒计时时间
    10. */
    11. function setTime(btnSendCode, countdown) {
    12. if (countdown == 0) {
    13. btnSendCode.attr('disabled', false);
    14. btnSendCode.text("获取验证码")
    15. return;
    16. } else {
    17. btnSendCode.attr('disabled', true);
    18. btnSendCode.text("重新发送(" + countdown + ")");
    19. countdown--;
    20. }
    21. setTimeout(function () {
    22. setTime(btnSendCode, countdown)
    23. }, 1000)
    24. }