控制按钮提示,点击后,一段时间内按钮不可用

js

/**
 * 点击按钮后多长时间内按钮不可点 
 * @param time 时间 以秒为单位 
 * 可接受 id 及 class 选择器,可同时控制多少个class
 */
$.fn.setBtnTimer = function(options) {
	"use strict";
	var defaults = {
		'time': 60
	};
	var settings = $.extend({},defaults, options);
	this.attr("disabled","disabled");
	var that = this,
		oldv = that.val(),
		timer,
		tick = function(){
			settings.time--;
			that.val(settings.time+'s后可在此操作');
			if(settings.time<1){
				that.removeAttr("disabled");
				window.clearInterval(timer);
				that.val(oldv);
			}
		};
	return this.each(function(){
		timer = window.setInterval(tick, 1000);
	});
}

html


	
    

	
    
    


你可能感兴趣的:(jquery,html)