简体   繁体   English

标签在新窗口中提交表单,为什么?

[英]tabs submiting form on new window, why?

I have an issue here. 我这里有一个问题。

I've been using Tabs (widget jqueryUi). 我一直在使用Tabs (widget jqueryUi)。

All seems to work fine, but sometimes when I submit a form (inside the tab), the result comes in the window and not in the tabdiv. 一切似乎都正常,但是有时当我提交表单(在选项卡内部)时,结果出现在窗口中,而不是在tabdiv中。

I don't want that, the client has to keep in the websystem. 我不希望那样,客户端必须保留在网络系统中。

I already tried putting target="_self" in the form, but keep doing the issue sometimes. 我已经尝试过将target="_self"放入表单中,但有时会继续执行此问题。

var $tabs = $("#main").tabs({
    tabTemplate: "<li><a href='#{href}'>#{label}</a> <span class='ui-icon ui-icon-close notext inline'>Remove Tab</span></li>",
    idPrefix: "tab_",
    add:function(e, ui){
        $tabs.tabs('select', '#' + ui.panel.id).show("blind");
        $j( "#list_tabs .ui-icon-close:last" ).on( "click", function(e, elemento) {
            var index = $( "li", $("#main").tabs() ).index( $( this ).parent() );
            $("#main").tabs( "remove", index );

            desativarItemSubmenu($('#' + $(this).parent()[0].id.replace('tab_', '')));
        });
    },

    select: function(event, ui){
        var id = $(ui.tab).parent()[0].id;
        if(id)
            ativarItemSubmenu($('#' + id.replace('tab_', '')));
    },
    cache:true,
    ajaxOptions: {async: false,cache: false}
})


$(".anchor").live("click", function(){
    if("<?php echo $this->session->userdata("cod_usuario") ?>" == ""){
        window.location.reload;
    }
    var url = this.rel;
    var tab_title = this.text;
    var tab_id = "tab_"+this.id;

    if(!$('#' + tab_id).length){
        if($('#main').tabs('length') > 3)
            $("#main").tabs("remove", 3);

        $("#main").tabs("add", url, tab_title);
        $("#list_tabs li:last").attr("id", tab_id); 
        $("#list_tabs li:last").addClass("active");
    }
    else{
        $('#main').tabs('option', 'selected', $('#' + tab_id).index());
    }
})

// Remove a tab clicando no "x" (remove tab by click on "x")
$( "#main span.ui-icon-close" ).live( "click", function() {
    var index = $( "li", $("#main").tabs() ).index( $( this ).parent() );
    $("#main").tabs( "remove", index );
});

I am not fully confident about this answer, but if not the solution then perhaps it will give you ideas that could lead to the solution. 我对这个答案并不完全有信心,但是如果没有解决方案,那么也许它将为您提供可能导致解决方案的想法。

It appears that you are changing the ID attribute of tabs on the fly. 看来您正在即时更改选项卡的ID属性。 When you change an element's ID, you remove it from the DOM -- or rather, you re-inject it as a new element into the DOM. 更改元素的ID时,会将其从DOM中删除-或更确切地说,您将其作为新元素重新注入DOM中。 Therefore, any javascript that was previously bound to that element is no longer bound. 因此,不再绑定任何以前绑定到该元素的javascript。 Since you are using jQuery UI tabs, the changed element may stop being a tab. 由于您使用的是jQuery UI标签,因此更改后的元素可能不再是标签。

This could cause the type of problem that you are describing. 这可能会导致您描述的问题类型。

Solution: instead of changing the tab ID, refactor your code to use classes that you add/remove. 解决方案:无需更改选项卡ID,而是将代码重构为使用添加/删除的类。

As a general rule, use great caution when changing IDs on the fly. 通常,在动态更改ID时要格外小心。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM