以前做popup效果,要对每一个写一个函数,这样如果多了,函数也就太多了,感觉太麻烦了。
所以自己用jQuery写了一个通用的函数,用起来很方便,也很简单
代码如下:
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 <html xmlns="http://www.w3.org/1999/xhtml">
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>popup效果</title>
6 <script type="text/javascript" src="http://common.cnblogs.com/script/jquery.js"></script>
7 <script type="text/javascript">
8 $(function() {
9 var target = $("a");
10
11 target.each(function(){
12 $(this).click(function() {
13 var popUrl = $(this).attr("href");
14 window.open(popUrl,'newWindow','width=800,height=600,left=300px,top=100px,menubar=no.scrollBars=no,status=no,location=no,toolbar=no,resizable=no');
15 return false;
16 })
17 });
18 });
19 </script>
20
21 </head>
22 <body>
23 <ul>
24 <li><a href="http://www.baidu.com">点击我弹出百度</a></li>
25 <li><a href="http://www.google.com">点击我弹出谷歌</a></li>
26 </ul>
27 </body>
28 </html>
2 <html xmlns="http://www.w3.org/1999/xhtml">
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>popup效果</title>
6 <script type="text/javascript" src="http://common.cnblogs.com/script/jquery.js"></script>
7 <script type="text/javascript">
8 $(function() {
9 var target = $("a");
10
11 target.each(function(){
12 $(this).click(function() {
13 var popUrl = $(this).attr("href");
14 window.open(popUrl,'newWindow','width=800,height=600,left=300px,top=100px,menubar=no.scrollBars=no,status=no,location=no,toolbar=no,resizable=no');
15 return false;
16 })
17 });
18 });
19 </script>
20
21 </head>
22 <body>
23 <ul>
24 <li><a href="http://www.baidu.com">点击我弹出百度</a></li>
25 <li><a href="http://www.google.com">点击我弹出谷歌</a></li>
26 </ul>
27 </body>
28 </html>