Asp.net 如何在不同选项卡中设置默认按钮?

Asp.net 如何在不同选项卡中设置默认按钮?,asp.net,defaultbutton,Asp.net,Defaultbutton,我有一个包含4个不同选项卡的内容页。我使用以下jQuery来控制选项卡。我需要为每个选项卡设置默认按钮,这样当用户单击Enter时,默认按钮的事件将被触发 按键应该可以完成这项工作。但不知何故,当我单击Enter时,页面被重新加载,而不是提交 如何更改代码,使页面根据激活的用户控件或选项卡确定哪个按钮是默认按钮 $(document).ready(function() { var selected_tab = document.getElementById("<%=hfSelect

我有一个包含4个不同选项卡的内容页。我使用以下jQuery来控制选项卡。我需要为每个选项卡设置默认按钮,这样当用户单击Enter时,默认按钮的事件将被触发

按键应该可以完成这项工作。但不知何故,当我单击Enter时,页面被重新加载,而不是提交

如何更改代码,使页面根据激活的用户控件或选项卡确定哪个按钮是默认按钮

$(document).ready(function() {
    var selected_tab = document.getElementById("<%=hfSelectedTab.ClientID %>");
    //When page loads...
    $(".tab_content").hide(); //Hide all content
    if (selected_tab.value == 2) {
        $("ul.tabs li:nth-child(2)").addClass("active").show();
        $(".tab_content:nth-child(2)").show();
    }
    else if (selected_tab.value == 3) {
        $("ul.tabs li:nth-child(3)").addClass("active").show();
        $(".tab_content:nth-child(3)").show();
    }
    else if (selected_tab.value == 4) {
        $("ul.tabs li:nth-child(4)").addClass("active").show();
        $(".tab_content:nth-child(4)").show();
    }
    else {
        $("ul.tabs li:first").addClass("active").show(); //Activate first tab
        $(".tab_content:first").show(); //Show first tab content
    }

    //On Click Event
    $("ul.tabs li").click(function() {
        $("ul.tabs li").removeClass("active"); //Remove any "active" class
        $(this).addClass("active"); //Add "active" class to selected tab
        $(".tab_content").hide(); //Hide all tab content

        var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
        $(activeTab).fadeIn(); //Fade in the active ID content

        if (activeTab == "#tab1")
            selected_tab.value = 1;
        else if (activeTab == "#tab2")
            selected_tab.value = 2;
        else if (activeTab == "#attachmentcontent")
            selected_tab.value = 3;
        else if (activeTab == "#kb") {
            selected_tab.value = 4;
            document.getElementById("<%=txtRootCause.ClientID %>").focus();
        }

        return false;
    });

    $("form input").keypress(function(e) {
        if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
            $('button[type=submit] .default').click();
            return true;
        }
    });
});
$(文档).ready(函数(){
var selected_tab=document.getElementById(“”);
//当页面加载时。。。
$(“.tab_content”).hide();//隐藏所有内容
如果(所选值=2){
$(“ul.tabs li:nth child(2)”).addClass(“active”).show();
$(“.tab_内容:第n个子项(2)”).show();
}
else if(所选值=3){
$(“ul.tabs li:nth child(3)”).addClass(“active”).show();
$(“.tab_内容:第n个子项(3)”).show();
}
else if(所选值=4){
$(“ul.tabs li:nth child(4)”).addClass(“active”).show();
$(“.tab_内容:第n个子项(4)”).show();
}
否则{
$(“ul.tabs li:first”).addClass(“active”).show();//激活第一个选项卡
$(“.tab_content:first”).show();//显示第一个选项卡内容
}
//点击事件
$(“ul.tabs li”)。单击(函数(){
$(“ul.tabs li”).removeClass(“active”);//删除任何“active”类
$(this).addClass(“active”);//将“active”类添加到所选选项卡
$(“.tab_content”).hide();//隐藏所有选项卡内容
var activeTab=$(this).find(“a”).attr(“href”);//查找href属性值以标识活动选项卡+内容
$(activeTab).fadeIn();//淡入活动ID内容
如果(activeTab==“#tab1”)
所选的_tab.value=1;
else if(activeTab==“#tab2”)
所选_tab.value=2;
else if(activeTab==“#附件内容”)
所选_tab.value=3;
else if(activeTab==“#kb”){
所选_tab.value=4;
document.getElementById(“”.focus();
}
返回false;
});
$(“表单输入”)。按键(功能(e){
if((e.which&&e.which==13)| |(e.keyCode&&e.keyCode==13)){
$('button[type=submit].default')。单击();
返回true;
}
});
});

我的解决方案是将每个选项卡(由div定义)包装在asp:Panel中,并设置Panel DefaultButton属性