我有两个div
s。当事件被触发时,我想显示一个div
(里面有其他的)。div
onclick
任何帮助或建议将不胜感激。
干得好:
div{
display: none;
}
document.querySelector("button").addEventListener("click", function(){
document.querySelector("div").style.display = "block";
});
<div>blah blah blah</div>
<button>Show</button>
现场演示:http: //jsfiddle.net/DerekL/p78Qq/
You'll have to give an ID to the div you want to show/hide, then use this code:
html:
<div id="one">
<div id="tow">
This is text
</div>
<button onclick="javascript:showDiv();">Click to show div</button>
</div>
javascript:
function showDiv() {
div = document.getElementById('tow');
div.style.display = "block";
}
CSS:
#tow { display: none; }
Fiddle: http://jsfiddle.net/xkdNa/
如果你有 div 的 ID,试试这个:
<input type='submit' onclick='$("#div_id").show()'>
function showstuff(boxid){
document.getElementById(boxid).style.visibility="visible";
}
<button onclick="showstuff('id_to_show');" />
我想这会对你有所帮助。