2014-04-01 23 views

回答

0

,你可以做到這一點的JavaScript Closures

在你的HTML,

<a href="#" id="myButton" title="">Click Me!</a> 

而在你的JS,

(function(){ 
    var click_counter = 0; 
    $('#myButton').on('click', function(event){ 
     event.preventDefault(); 
     var el = jQuery(this); 
     click_counter += 1; 
     if (!el.hasClass('inactive')){ 
      // should be activated 
      alert('You have clicked the link ' + click_counter + ' once , And this will be disabled'); 
     }; 
     if (click_counter >= 1){ 
      // deactivate 
      el.addClass('inactive'); 
     }; 
    }); 
})(); 

,並說明你的按鈕被點擊,添加此class to your CSS

a.inactive { 
    color: gray; 
    text-decoration: line-through; 
} 

希望這會有所幫助!

+0

謝謝,但你能否給我一些建議,在48小時內過期鏈接 – user3440874

+0

@ user3440874如果上面的代碼適合你,請將其標記爲答案,以便它可以幫助其他人識別 –

相關問題