JavaScript总结之单击弹出div

时间:2024-01-19 12:01:38

今天也算用了不少手段来实现他们的要求,大概记录一下,下边的代码示例,我全部修改贴出来,争取全部占到自己的代码里就能用。

1、点击同一个div,打开/关闭另一个div。

  1 <script type="text/javascript" src="jquery-1.11.1.min.js"></script>
2 <script type="text/javascript">
3 /*var btnShow=document.getElementById('show_detail');
4 var detail=document.getElementById('detail');
5 btnShow.onclick=function(){
6 if(detail.style.display=="none"){
7 detail.style.display="block"
8 }else{
9 detail.style.display="none";
10
11 }
12
13 }*/
14 $(function(){
15 $("#show_detail").click(function(){
16 $('#detail').toggle('fast');
17 })
18 })
19 </script>

然后是html代码,大概做了个简单的:

 <div class="content" style="width:400px;">
<div id="show_detail" align="right" style="margin-right:20px; color:#00F; cursor:pointer;">[详细信息]</div>
<div id="detail" align="left" style="display:none; height:150px; overflow:auto; padding:10px;">
<hr />
<br />
<p>弹出框:</p>
<p style="line-height:25px;">欢迎访问,有何问题欢迎交流<br />
</p>
</div>
<p style='text-align:center'><b><span style='font-size:1.5em'>&raquo;</span> 返回 <a href="javascript:history.back()">上一层</a></b></p>
</div>

隐藏部分的也可以,不过显示效果不如下边jquery写的。slow和fast是显示速度,效果还不错。

实现效果:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAZ8AAABfCAIAAAC4H13DAAADuklEQVR4nO3dXXLaMACFUe0oy+mSspQsJUvpW7ZAHwiQYluWbGycyznDQ7HlHzrTbyTDTMsJIFF59g0AbELdgEzqBmRSNyCTugGZ1A3IpG5AJnUDMqkb/Hpl8O94uGVqY9eZ28+w4FoPd4BbAKpKub1+brwbU3lb2Th76QUnmR0z+okeTt3g6KYSMBW7lrT97EslNOeNo4OHhzQOa/loD6FucHQtdWs/yTVYo9sXn78yXt2AcfUEtMyYhn/eqG7mbkCHlc/yR0MzW7dhH2ebZe4G9Kk83qqPrOztrVvjfZq7AR1m50QLJlb1ut2tXh91n1271lM3OLr2anSNnAriVO9aAmruBnRYWbfR1mz0rULX9gW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yqBGRRJSCLKgFZVAnIokpAFlUCsqgSkEWVgCyqBGRRJSCLKgFZVAnIokpAFlUCsqgSkEWVgCyqBGRRJSCLKgFZVAnIokpAFlUCsqgSkEWVgCyqBGRRJSCLKgFZVAnIokpAFlUCsqgSkEWVgCyqBGRRJSCLKgFZVAnIokpAFlUCsqgSkEWVgCyqxOVyuUzTNE3POxmm6ec0/Xza7ngtqhTvv3/+mqbp73+XnjctdWf6UzFraNeXdGKVPra8+u+MXXMUVXoB//49TdP01z//LTzvunakWZZH5q4dyblV+pJdcxRVegUfw6PPAdKv51u7dFel/vI75q5tWZVYpEqv4WN49Bmi388338hdLpftVRreuCVXyR3cS1OlF/F7uHQN0X2ntmh+TjQM0EtU6Ywt8zSq9DI+u/QRps/nK2FqDnOeX6UzhjCq9A2o0qu4j9Bs8LTuLijD1hTLFxO3an760/+3dcV9h81zqNKL+H3D9sgN3Dwo8zzVyy9N3ModHAVVegm/B0a/G3T/Q7meujJbl1clTqJKr+DXwOjaoJ2/sPTgWOlu4eQquYl7aaoUb/bLSR9N2vE7Adem/Pjx49IYMdXdSa7SE3bEeVTpjdxWad6UzpT+3LUjeUaVFOpFqdK7qG/WVldZsvdgTglEkaRT98uxVOktzG/WOqE5aqy0+8f827/MX6v7UOmlqRKn21qlp/376heGMVUCsqgSkEWVgCyqBGRRJSCLKgFZVAnIokpAFlUCsqgSkEWVgCyqBGRRJSCLKgFZVAnIokpAFlUCsqgSkEWVgCyqBGRRJSCLKgFZVAnIokpAFlUCsqgSkEWVgCyqBGRRJSCLKgFZVAnI8n+Sp/XIz7+JrgAAAABJRU5ErkJggg==" alt="" />

再次点击回复初始。

本想都写一个的。发现这样的话会很长,分着写吧。到时候在写一个索引便好。