2014-04-10 31 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 
     } 
    }); 
});