js 点击某一块就显示某一块

 1 function modelClick(n) {
 2     $("div[id*=model]").each(function (i) {  //找到以id为model开头的div
 3         i == n ? $(this).show() : $(this).hide();
 4     });
 5     return false;
 6 }
 7 
 8 
 9 
10 $("div.time div").each(function (i) {
11         $(this).click(function () {
12             modelClick(i);
13         });
14         if (i == 2) { //显示第3个模块
15             this.click();
16         }
17     });

算是小技巧吧.

至少可以不用$("#xx").hide这样一个一个写了.

posted on 2013-08-23 15:47  刘阿毛  阅读(359)  评论(0编辑  收藏  举报

导航