取消選擇所有選項
如果你指的是更新用戶界面,你可以明確地從所有的按鈕(或在您的案件標籤)刪除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](https://i.stack.imgur.com/zAtns.gif)
設到第一個選項
同樣的,如果你想將其設置爲它的初始選項,你可以簡單地觸發第一元素的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](https://i.stack.imgur.com/wU6YA.gif)
我假設上點擊復位要恢復預選即#選項1,應再次選擇。 – sahil