这个例子:
<h3>123</h3>
<div>123456</div>
点击h3一下div消失,再点击一下出现,这样用js怎样实现非JQ,就是每一次点击执行不同函数
代码如下
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <body> <h3>123</h3> <div>123456</div> <script type="text/javascript"> var oH3=document.getElementsByTagName("h3")[0]; var oDiv=document.getElementsByTagName("div")[0]; oH3.toggle; oH3.onclick = function(){ if((this.toggle=="hide") || (this.toggle == undefined)){ oDiv.style.display="none"; oH3.toggle = "show"; }else{ oDiv.style.display="block"; oH3.toggle = "hide"; } } </script> </body> </html>
document.getElementsByTagName('你要查找的div').style.display = "none" 隐藏
document.getElementsByTagName('你要查找的div').style.display = "block" 显示