2016-04-22 52 views
0

这是一个重复的问题,但我找不到答案。你如何重置引导单选按钮?reset bootstrap单选按钮

根据文档它被重置,但它没有看到做任何事情我也尝试使用jQuery来改变它,但没有。

$('#Reset').click(function(){ 
$('#option1').button('reset'); 
    $("#option1").prop('checked', true); 
}); 

这里是小提琴。 https://jsfiddle.net/m1jryanh/我点击不同的按钮,然后按重置按钮,希望它会重置,但它没有。

+0

我假设上点击复位要恢复预选即#选项1,应再次选择。 – sahil

回答

1

您只需在#option1进行点击。

$('#Reset').click(function(){ 
    $("#option1").click(); 
}); 

这是更新的fiddle

0

取消选择所有选项

如果你指的是更新用户界面,你可以明确地从所有的按钮(或在您的案件标签)删除active类本身:

$('#Reset').click(function(){ 
    // Explicitly uncheck all of your radio buttons 
    $('[data-toggle="buttons"] :radio').prop('checked', false); 
    // Select all label elements within your toggle and remove the active class 
    $('[data-toggle="buttons"] label').removeClass('active'); 
}); 

您可以see this in action here和演示如下:

enter image description here

设到第一个选项

同样的,如果你想将其设置为它的初始选项,你可以简单地触发第一元素的click事件:

$('#Reset').click(function(){ 
    // Explicitly uncheck all of your radio buttons 
    $('[data-toggle="buttons"] :radio').prop('checked', false); 
    // Select all label elements within your toggle and remove the active class 
    $('[data-toggle="buttons"] label').removeClass('active'); 

    // Set the first one as checked and selected 
    $('[data-toggle="buttons"] :radio:first').addClass('active'); 
    // Do the same thing for the active indicator 
    $('[data-toggle="buttons"] label:first').addClass('active'); 
}); 

可以see this option in action here和证明如下:

enter image description here

0

您应该删除active类并取消选中下面的单选按钮。

$('#Reset').click(function() { 
    $('.btn-group :radio').prop('checked', false); 
    $('.btn-group .active').removeClass('active'); 
}); 

DEMO