2012-03-26 138 views

回答

0

您應該使用

$('#demo').show(); // to display 

$('#demo').hide(); // to hide the div 
0

使用hide() method

$("#demo").hide() 

$("#demo").hide() 

甚至toggle() method切換能見度:

$("#demo").toggle() 
在您的示例

綜合:從jQuery的documentation

​​

實施例:

<h1 class="firstHeading" style="display: block;">Tutorials:Basic Show and Hide</h1> 
<div class="examples"> 
    <input id="hideh1" type="submit" value="Hide site tile" name="hideh1"> 
    <input id="showh1" type="submit" value="Show site title" name="showh1"> 
    <input id="toggleh1" type="submit" value="Toggle site title" name="toggleh1"> 
</div> 

<script type="text/javascript"> 
    $(document).ready(function() { 
     $(document).ready(function() { 
      $('#hideh1').click(function() { 
       $('div.showhide,h1').hide(); 
      }); 
      $('#showh1').click(function() { 
       $('div.showhide,h1').show(); 
      }); 
      $('#toggleh1').click(function() { 
       $('div.showhide,h1').toggle(); 
      }); 
     }); 
    }); 
</script> 
1

試試這個,最簡單的一個..

<input type="button" onclick="$('#demo').toggle()" value="clicking me should unhide a div tag"> 
0

$(document).ready(function() { 
    $("input[type='button']").click(function() { 
     $("#demo").show(); 
    }); 
}); 

document.getElementById("demo").style.display = "block"; 
0

$("#demo").style不是一個jQuery函數

您應該使用$("#demo").css("display","block")屬性或使用show()toggle()函數

2
$("#button").click(function() { 
     $("#div").hide(); 
}); 
$("#button").click(function() { 
    $("#div").show(2000); 
}); 
0

您無法通過訪問jQuery對象的屬性。 (點)(它們不是JavaScript對象)

你,

$('#demo').css({'display':'none'}) 

或者你可以使用$('#demo').hide();(它的快捷方式)

0

jQuery.hide() is very slow

改用以下:

document.getElementById('demo').style.display = 'none' 

這是你聽到style財產。該屬性適用於DOM對象。 jQuery對象不是DOM對象。