2016-12-15 39 views
1
$(document).ready(function() { 
    var clicks = 0; 
    $(".next-button").click(function() { 
     clicks++; 
     $('.figure').html(clicks); 
    }); 
    console.log(clicks); 

    if (clicks == 2) { 
     $('.next-button').click(function() { 

      var nextTab = $('ul.tabs div.orange-tab.current').next(); 


      $('ul.tabs div.orange-tab').removeClass('current'); 
      $('div.tab-content').removeClass('current'); 

      nextTab.addClass('current'); 
      $('div[id=' + nextTab.attr('data-tab') + ']').addClass('current'); 


     }); 
    } else { 
     //function to hide the button 
    } 

}); 

嗨,我有這個功能,我想,當我按一下按鈕,增加計數器,如果大於2,例如隱藏按鈕..隱藏按鈕,當計數器的值大於2

<div id="next-button" class="text-center"> 
    button id="next_button" name="next_button" class="next-button">Next</button> 
</div> 
+0

'$( '#下按鈕')。隱藏()'也ID必須是唯一的,你忘了'<'在按鈕 – iHasCodeForU

+0

你'如果(點擊== 2)'應該是裏面$(「。next-button」)。click(function()' –

+0

chnage if(點擊<= 2){//} else {} –

回答

0

你可以試試這個代碼:

$(document).ready(function() { 
    var clicks = 0; 
    $(".next-button").click(function(){ 
     clicks = clicks+1; 
     $('.figure').html(clicks); 
     if(clicks>2){ 
       $(this).hide(); 
     } 
    }); 
}); 
0

你可以試試這個。適合我!

<!DOCTYPE html> 
<html> 
<head> 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
<script></script> 
<script> 
$(document).ready(function() { 
     var clicks = 0; 
    $(".next-button").click(function() { 
    alert('hello'); 
     clicks++; 
     alert(clicks); 
     //$('.figure').html(clicks); 
     if(clicks==2) 
     { 

      $("#hide_button").hide(); 
     } 
    }); 
}); 
</script> 
<title>Page Title</title> 
</head> 
<body> 

<h1>This is a Heading</h1> 
<p>This is a paragraph.</p> 
<div id="next-button" class="text-center"> 
    <button id="next_button" name="next_button" class="next-button">Next</button> 
    <button id="hide_button" name="next_button" class="next-button">Hide Me</button> 
</div> 
</body> 
</html>