如下,如何同时调用两个这样相同的方法,比如.nwj_conttab1和.nwj_conttab2这两个内容框是通过ul.nwj_ul1 li和ul.nwj_nl2 li来控制TAB,已经尝试过把两个需要的样式用","分割,无果,只有一个产生效果$(document).ready(function() { //Default Action
$(".nwj_conttab1").hide(); //Hide all content
$("ul.nwj_ul1 li:first").addClass("active").show(); //Activate first tab
$(".nwj_conttab1:first").show(); //Show first tab content
//On Click Event
$("ul.nwj_ul1 li").click(function() {
$("ul.nwj_ul1 li").removeClass("active"); //Remove any "active" class
$(this).addClass("active"); //Add "active" class to selected tab
$(".nwj_conttab1").hide(); //Hide all tab content
var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
$(activeTab).fadeIn(); //Fade in the active content
return false;
});});
$(".nwj_conttab1").hide(); //Hide all content
$("ul.nwj_ul1 li:first").addClass("active").show(); //Activate first tab
$(".nwj_conttab1:first").show(); //Show first tab content
//On Click Event
$("ul.nwj_ul1 li").click(function() {
$("ul.nwj_ul1 li").removeClass("active"); //Remove any "active" class
$(this).addClass("active"); //Add "active" class to selected tab
$(".nwj_conttab1").hide(); //Hide all tab content
var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
$(activeTab).fadeIn(); //Fade in the active content
return false;
});});
解决方案 »
- js怎样清空某个false的缓存
- ajax异步出错
- 如何实现body.style.overflow-x的隐藏 100分送上
- 是不是JavaScripti不能在FireFox上运行?
- js第二次调用提示缺少函数(急救!!!!)
- 初学js,问一个简单js代码,大家给看看??(总提示document.all(...)为空或不是对象,我想选1出层1,选2出层2)
- dojo grid 排序 大神帮忙看一下(dojox.grid.DataGrid)
- 如何判断页面的中的控件是否被改动过。?
- ActiveX文档服务器的几个问题,希望得到指点!
- 这样怎么做?
- 罕见的Js错误: typeerror:object #<a Document> has no method 'load'
- 求写个for循环,两篇帖子分一起送了!
$("ul.nwj_ul1 li").removeClass("css1").removeClass("css2");
Jquery 链式调用 试试行不行
这个TAB本身是正常移除active样式,但当页面有两处都要用这个TAB的时候,第二个TAB在移除、添加active样式时就无效,反而使用第二个TAB切换的时候,第一个有效果,第二个无反应
$(".nwj_conttab1").hide(); //Hide all content
$("ul#nwj_ul1 li:first").addClass("active").show(); //Activate first tab
$(".nwj_conttab1:first").show(); //Show first tab content
//On Click Event
$("ul#nwj_ul1 li").click(function() {
$("ul#nwj_ul1 li").removeClass("active"); //Remove any "active" class
$(this).addClass("active"); //Add "active" class to selected tab
$(".nwj_conttab1").hide(); //Hide all tab content
var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
$(activeTab).fadeIn(); //Fade in the active content
return false;
});});$(document).ready(function() { //Default Action
$(".nwj_conttab2").hide(); //Hide all content
$("ul#nwj_ul2 li:first").addClass("active").show(); //Activate first tab
$(".nwj_conttab2:first").show(); //Show first tab content
//On Click Event
$("ul#nwj_ul2 li").click(function() {
$("ul#nwj_ul2 li").removeClass("active"); //Remove any "active" class
$(this).addClass("active"); //Add "active" class to selected tab
$(".nwj_conttab2").hide(); //Hide all tab content
var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
$(activeTab).fadeIn(); //Fade in the active content
return false;
});});
}
里加一个参数提成另一个方法 不行么?
function init(idx){
$(".nwj_conttab"+idx).hide(); //Hide all content
$("ul#nwj_ul"+idx+" li:first").addClass("active").show(); //Activate first tab
$(".nwj_conttab"+idx+":first").show(); //Show first tab content
}$.ready(function(){
init(1);
init(2);
})
http://topic.csdn.net/u/20110107/14/4e2228b8-e0ad-4806-81c3-5c67e8ff2e6e.html完了做成了实例:
http://www.joomlask.com/joomla/front-end-development/item/168-base-on-jquery-tabs-slide-in-one-page.html