File tree Expand file tree Collapse file tree 1 file changed +10
-8
lines changed
Expand file tree Collapse file tree 1 file changed +10
-8
lines changed Original file line number Diff line number Diff line change 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 ) ;
2630 function sendSms ( opts ) {
2731 var url = getUrl ( opts ) ;
2832 var requestData = getRequestData ( opts ) ;
29-
3033 $ . ajax ( {
3134 url : url ,
3235 type : 'post' ,
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' ) {
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 }
You can’t perform that action at this time.
0 commit comments