1.JavaScript把控件id作为参数调用
<script type="text/javascript"> function xx(pmba) { document.getElementById(pmba).style.display = "block"; } </script>
<div id="overlay"> <input type="button" value="弹出A" onclick="xx('xa')" /><input type="button" value="弹出B" onclick="xx('xb')" /> </div> <div class="win" id="xa"> 网页a</div> <div class="win" id="xb">窗口b</div>
2.这个弄了好一会儿,只写一个Jqurey函数,通过调用不同的控件id作为参数就好了,开始不会啊,老出错
<script type="text/javascript" src="jQuery 2.0.3.js"></script> <script type="text/javascript"> function ShowMsg(xdiv)//调用函数时,传入控件id { var box = 300; var th = $(window).scrollTop() + $(window).height() / 1.6 - box; var h = document.body.clientHeight; var rw = $(window).width() / 2 - box; $('#'+ xdiv).animate({ top: th, opacity: 'show', width: 600, height: 340, right: rw }, 500);//最主要就是这个<span style="color:#FF0000;">$('#'+ xdiv)</span> return false; } function CloseMsg(ydiv) { $("#"+ydiv).animate({ top: 0, opacity: 'hide', width: 0, height: 0, right: 0 }, 500); } </script>