Skip to content

Commit fcd2892

Browse files
committed
update
1 parent 610af20 commit fcd2892

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

js/laravel-sms.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,20 @@
77
* Date 2015/06/08
88
*/
99
(function($){
10-
var _this, btnOriginContent;
10+
var _this, btnOriginContent, timeId;
1111

1212
$.fn.sms = function(options) {
1313
var opts = $.extend(
1414
$.fn.sms.defaults,
1515
options
1616
);
17-
_this = this;
18-
19-
_this.on('click', function (e) {
17+
var self = this;
18+
self.on('click', function (e) {
19+
if (typeof _this !== 'undefined') {
20+
clearTimeout(timeId);
21+
changeBtn(btnOriginContent, false);
22+
}
23+
_this = self;
2024
btnOriginContent = _this.html() || _this.val() || '';
2125
changeBtn('短信发送中...', true);
2226
sendSms(opts);
@@ -26,7 +30,6 @@
2630
function sendSms(opts) {
2731
var url = getUrl(opts);
2832
var requestData = getRequestData(opts);
29-
3033
$.ajax({
3134
url : url,
3235
type : 'post',
@@ -59,7 +62,6 @@
5962
var requestData = {
6063
_token: opts.token || ''
6164
};
62-
6365
var data = $.isPlainObject(opts.requestData) ? opts.requestData : {};
6466
for (var key in data) {
6567
if (typeof data[key] === 'function') {
@@ -68,18 +70,18 @@
6870
requestData[key] = data[key];
6971
}
7072
}
71-
7273
return requestData;
7374
}
7475

7576
function timer(seconds) {
7677
if (seconds >= 0) {
77-
setTimeout(function() {
78+
timeId = setTimeout(function() {
7879
changeBtn(seconds + ' 秒后再次发送', true);
7980
seconds -= 1;
8081
timer(seconds);
8182
}, 1000);
8283
} else {
84+
clearTimeout(timeId);
8385
changeBtn(btnOriginContent, false);
8486
}
8587
}

0 commit comments

Comments
 (0)