2015-03-02 78 views
0

我試過這個腳本,但是運行時沒有發生任何事情。 jquery點擊href顯示div不能正常工作

<a href="#sign_up">sign up</a> 
 

 
<script> 
 
$('a[href = "#sign_up"]').click(function(){ 
 
    $("#signup").show(); 
 
    $("#page").hide(); 
 
    }); 
 
</script>

+0

你只需要做'$( 「#註冊」)點擊(函數(){' – kidA 2015-03-02 10:21:11

+0

檢查div id是否爲'#signup'或'#sign_up'。 – Jai 2015-03-02 10:26:14

+0

你的代碼有效,但你需要包含jQuery庫,下面是你的確切代碼工作的jsfiddle:http:// jsfiddle.net/80aewwz6/ – Neel 2015-03-02 10:26:45

回答

0

改變這一點:

$('a[href="#sign_up"]').click(function(e){ // remove the spaces 
    e.preventDefault(); // pervent the jump 
    $("#sign_up").show(); // check this id 
    $("#page").hide(); 
}); 
0

使用此

<a href="#sign_up" id="sign_up">sign up</a> 

<script> 
$('#sign_up').click(function(){ 
    $("#signup").show(); 
    $("#page").hide(); 
    }); 
</script>