Jquery tabs

白馬酒涼發表於2013-09-18

官網
http://api.jqueryui.com/tabs/


必須通過了後臺驗證tab1的資訊後才允許進入tab2

        var passed=false;
         $("#tabs").tabs({
            event: "click",
            active: 0,
            beforeActivate: function (event, ui) {
                if (ui.newTab.text() == "Tab2") {
                  $('#tabs-1 .validationMsg').hide();
                    var ok = true;
                    if (!passed ) {
                        ok = validate();  //前臺validation
                    }

                    var toDo = function () {
                        passed = true;
                        $('#tabs').tabs("option", "active", 1);
                        //$('#tabs ul li:eq(1) a').focus();
                    }

                    var notToDo = function () {
                        passed = false;
                        var errorMsg = $('#tabs-1 .validationMsg').html();
                        // event.preventDefault();
                        // ui.oldTab.focus();
                        $('#tabs').tabs("option", "active", 0);
                        $('#tabs ul li:eq(0) a').focus();
                        setTimeout("$('#tabs-1 .validationMsg').html('" + errorMsg + "');$('#tabs-1 .validationMsg').show();", 0);
                        return;
                    }

                    if (!ok) {
                        event.preventDefault();
                        notToDo();
                    }
                    else {
                        if (!passed) {
                            validate2($('#tabs-1'), '/controller/action', toDo, notToDo);  //後臺ajax驗證
                            event.preventDefault();
                        }
                    }

                }
            }
        });


 

 

相關文章