我跟随DIV。我想在点击按钮后显示DIV。现在显示无
<div style="display:none;" class="answer_list" > WELCOME</div>
<input type="button" name="answer" >
答案 0 :(得分:72)
HTML代码:
<div id="welcomeDiv" style="display:none;" class="answer_list" > WELCOME</div>
<input type="button" name="answer" value="Show Div" onclick="showDiv()" />
Javascript:
function showDiv() {
document.getElementById('welcomeDiv').style.display = "block";
}
答案 1 :(得分:11)
<强> HTML 强>
<div id="myDiv" style="display:none;" class="answer_list" >WELCOME</div>
<input type="button" name="answer" onclick="ShowDiv()" />
<强>的JavaScript 强>
function ShowDiv() {
document.getElementById("myDiv").style.display = "";
}
或者如果你想使用带有漂亮小动画的jQuery:
<input id="myButton" type="button" name="answer" />
$('#myButton').click(function() {
$('#myDiv').toggle('slow', function() {
// Animation complete.
});
});
答案 2 :(得分:4)
<script type="text/javascript">
function showDiv(toggle){
document.getElementById(toggle).style.display = 'block';
}
</script>
<input type="button" name="answer" onclick="showDiv('toggle')">Show</input>
<div id="toggle" style="display:none">Hello</div>
答案 3 :(得分:0)
<div style="display:none;" class="answer_list" > WELCOME</div>
<input type="button" name="answer" onclick="document.getElementsByClassName('answer_list')[0].style.display = 'auto';">