jQuery方法Toggle()应用
2013年01月28日
⁄ 综合
⁄ 共 1265字 ⁄ 字号
小 中 大
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" >
- <head>
- <title>toggle</title>
- <script type="text/javascript" src="../js/jquery-1.2.6.js"></script>
- <script type="text/javascript">
- //传f(id),此为正道,这里是传了object
- function f(obj){
- var id = $(obj).attr("id");
- $(".cc:not(#"+id+")").hide();//传过来的是id
- $(obj).toggle();//直接传值就是当id,#id
- }
- //传'id',此法不简化
- function ff(obj){
- $(".cc:not(#"+obj+")").hide();//仍然需要这样
- $("#"+obj).toggle();
- }
- </script>
- </head>
- <body>
- <div style="display:none;" id="Div1" class="cc">hello1</div>
- <input type="button" value="1" onclick="f(Div1);" />
- <div style="display:none;" id="Div2" class="cc">hello2</div>
- <input type="button" value="2" onclick="f(Div2);" />
- <div style="display:none;" id="Div3" class="cc">hello3</div>
- <input type="button" value="3" onclick="f(Div3);" />
- <div style="display:none;" id="Div4" class="cc">hello4</div>
- <input type="button" value="4" onclick="ff('Div4');" />
- <div style="display:none;" id="Div5" class="cc">hello5</div>
- <input type="button" value="5" onclick="ff('Div5');" />
- </body>
- </html>