2014-01-18 2 views
0

Я не могу понять, что я делаю неправильно. Вот ссылка, чтобы увидеть пример. http://atozcognac.com/hotel/form/# Мои предыдущие и следующие кнопки работают, но я не могу понять, как изменить вкладки, если пользователь нажимает prev или next. Спасибо за ваше время. $ (документ) .ready (функция() {Навигация по модальной форме

//When someone clicks on the navigation links 
$('.nav li').click(function(e){ 
    $('.nav li').attr('id', ''); //make all navtabs inactive 
    $(this).attr('id', 'activetab'); //make the one we clicked active 

    //hide all of the fieldsets 
    $('fieldset').attr('class', 'myHidden'); 

    whichitem=$(this).attr('title'); //get the title of the nav we clicked 

    //make the class of what we cleared not hidden 
    $("fieldset[title='"+whichitem+"']").attr('class', ''); 
}); 


//When someone clicks on the previous button 
$('.prev').click(function(e){ 
    var listItem = document.getElementById('activetab'); //find out which navtab is active 
    whichOne=$('li').index(listItem); //get the index of the navtab 

    $('.nav li').attr('id', ''); //make all the navtabs inactive 
    $(".nav li:eq("+(whichOne-1)+")").attr('id', 'activetab'); //make previous tab active 

    $('fieldset').attr('class', 'myHidden'); //hide all the fieldsets 
    $("fieldset:eq("+(whichOne-1)+")").attr('class', ''); //show the previous fieldset 
}); 


//When someone clicks on the next button 
$('.next').click(function(e){ 
    var listItem = document.getElementById('activetab'); //find out which navtab is active 
    whichOne=$('li').index(listItem); //get the index of the navtab 

    $('.nav li').attr('id', ''); //make all the navtabs inactive 
    $(".nav li:eq("+(whichOne+1)+")").attr('id', 'activetab'); //make next tab active 

    $('fieldset').attr('class', 'myHidden'); //hide all the fieldsets 
    $("fieldset:eq("+(whichOne+1)+")").attr('class', ''); //show the next fieldset 
}); 
    }); 

ответ

1

Вы можете вызвать событие щелчка и использовать логику вы уже реализованную в храповом слушателе. И я хотел бы использовать класс activetab вместо идентификатора .

$(document).ready(function(){ 
//When someone clicks on the navigation links 
$('.nav li').click(function(e){ 
    $('.nav li').removeClass("activetab"); //make all navtabs inactive 
    $(this).addClass("activetab"); //make the one we clicked active 

    //hide all of the fieldsets 
    $('fieldset').addClass("myHidden"); 

    var whichitem=$(this).attr('title'); //get the title of the nav we clicked 

    //make the class of what we cleared not hidden 
    $("fieldset[title='"+whichitem+"']").removeClass("myHidden"); 
}); 


//When someone clicks on the previous button 
$('.prev').click(function(e){ 
    // trigger the click 
    $(".activetab").prev().click(); 
}); 


//When someone clicks on the next button 
$('.next').click(function(e){ 
    // trigger the click 
    $(".activetab").next().click(); 
}); 
}); 
+0

Спасибо за быстрый ответ на какой-то причине до сих пор не работает для меня. – user2432772

+0

Я обновил код. Может быть, теперь он будет работать !? – friedi

+0

Спасибо за помощь, но до сих пор не работают , – user2432772

Смежные вопросы