以下是我尝试在 JOOMLA 扩展中使用的 Bootstrap 单选按钮。
<fieldset id="myEdit" class="radio btn-group">
<input type="radio" id="myEdit0" value="0">
<label for="myEdit0" class="btn active btn-danger">Yes</label>
<input type="radio" id="myEdit1" value="1">
<label for="myEdit1" class="btn">No</label>
</fieldset>
当我单击"is"时,此按钮工作正常,但当我单击“否”时,它完全没有响应。另一种方式是我的单选按钮只能工作一次。 。 .但是当我复制这个html时 JOOMLA 全局配置窗口,在那里工作正常。
期待有用的回复
最佳答案
好的,我在 JOOMLA 管理员端的 template.js 中找到了以下一段 js 代码。并按如下方式更改 html,它起作用了
<fieldset id="myEdit" class="radio btn-group">
<input type="radio" id="myEdit0" value="1" name="myEdit">
<label for="myEdit0" class="btn">Yes</label>
<input type="radio" id="myEdit1" value="0" name="myEdit">
<label for="myEdit1" class="btn btn-danger">No</label>
</fieldset>
模板.js
$(document).ready(function()
{
$('*[rel=tooltip]').tooltip()
// Turn radios into btn-group
$('.radio.btn-group label').addClass('btn');
$(".btn-group label:not(.active)").click(function()
{
var label = $(this);
var input = $('#' + label.attr('for'));
if (!input.prop('checked')) {
label.closest('.btn-group').find("label").removeClass('active btn-success btn-danger btn-primary');
if (input.val() == '') {
label.addClass('active btn-primary');
} else if (input.val() == 0) {
label.addClass('active btn-danger');
} else {
label.addClass('active btn-success');
}
input.prop('checked', true);
}
});
$(".btn-group input[checked=checked]").each(function()
{
if ($(this).val() == '') {
$("label[for=" + $(this).attr('id') + "]").addClass('active btn-primary');
} else if ($(this).val() == 0) {
$("label[for=" + $(this).attr('id') + "]").addClass('active btn-danger');
} else {
$("label[for=" + $(this).attr('id') + "]").addClass('active btn-success');
}
});
})
关于javascript - JOOMLA 中的 Bootstrap 单选按钮无法正常工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23027742/