もちろん、ローカルストレージを使用してタイムスタンプを設定し、jQueryを使用して無効なプロパティを簡単に設定できます。
クリックで無効にするには:
$('#myButton').on('click', function() {
var $this = $(this);
$this.prop('disabled', true);
localStorage.myButtonEnableAt = new Date().getTime() + 30000;
setTimeout(function(){
$this.prop('disabled', false);
localStorage.myButtonEnableAt = null;
}, 30000);
});
ページの読み込み時に、状態を確認します。
var now = new Date().getTime();
if (localStorage.myButtonEnableAt > now ) {
$('#myButton').prop('disabled', true);
setTimeout(function(){
$('#myButton').prop('disabled', false);
localStorage.myButtonEnableAt = null;
}, localStorage.myButtonEnableAt - now);
}
デモ: http: //jsfiddle.net/36JrM/-より高速なデモのために10秒無効に変更されました。ボタンをクリックします。5秒後、ページを更新すると、予想どおり5秒後に有効になります。