2014-04-10 213 views
-3

当条件满足时,我想显示一个隐藏的div,如下所示。Javascript显示隐藏的div

<script> 
jQuery.getJSON('http://freegeoip.net/json/', function(location) { 
    if (location.country_code == 'AU') { 
    jQuery.show(jQuery('#aus'));  
    } 
}); 
</script> 

<div id="aus" style="display:none;"> 
<div class="bottomBar"> 

This.. 

</div> 
</div> 
+0

你已经尝试过没有权利? – adripanico

回答

2

试试这个:

jQuery.getJSON('http://freegeoip.net/json/', function(location) { 
    if (location.country_code == 'AU') { 
    jQuery("#aus").show();  
    } 
}); 

请通过此:http://api.jquery.com/show/

+1

div#aus会给出什么? :) –

+0

@JoakimM:由于OP正在试图显示div div div是我用'div#aus'。 'div#aus'和'#aus'没有区别。无论如何编辑。 :) – Unknown

+0

@未知谢谢! – gg11

3

首先,你应该包装,在一个document.ready,第二你需要使用这个语法.show

jQuery(function() { // Wait for DOM to be ready 
    jQuery.getJSON('http://freegeoip.net/json/', function(location) { 
     if (location.country_code == 'AU') { 
     jQuery('#aus').show(); // Correct syntax for show method 
     } 
    }); 
});