Javascript显示隐藏的div

时间:2014-04-10 13:41:33

标签: javascript jquery html

我希望在满足条件时显示隐藏的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>

2 个答案:

答案 0 :(得分: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
      }
    });
});

答案 1 :(得分:2)

试试这个:

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

请仔细阅读:http://api.jquery.com/show/