2015-03-02 80 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>