让我解释一下我想要实现的目标。单击标签1将再次显示该按钮,我希望禁用与标签2和标签3相同的按钮。
JsFiddle - http://jsfiddle.net/yingchor/xjzutbr9/2/
<input type='radio' class='radio-button' name='one'>
<label>label 1</label>
<input type='radio' class='radio-button' name='two'>
<label>label 2</label>
<input type='radio' class='radio-button' name='three'>
<label>label 3</label>
<div class="show-one one box" style="display: none;">
<button>Button 1</button>
</div>
<div class="show-two two box" style="display: none;">
<button>Button 2</button>
</div>
<div class="show-three three box" style="display: none;">
<button>Button 3</button>
</div>
var radio_button = false;
$('input[type="radio"]').click(function() {
var inputValue = $(this).attr("name");
var targetBox = $("." + inputValue);
$(".box").not(targetBox).hide();
$(targetBox).fadeIn();
//alert('asd')
});
$('.radio-button').on("click", function(event) {
var this_input = $(this);
if (this_input.attr('checked1') == '1') {
this_input.attr('checked1', '1')
} else {
this_input.attr('checked1', '2')
}
$('.radio-button').prop('checked', false);
if (this_input.attr('checked1') == '1') {
this_input.prop('checked', false);
this_input.attr('checked1', '2');
} else {
this_input.prop('checked', true);
this_input.attr('checked1', '1')
}
});我应该如何改变我的脚本来实现这个目标呢?
发布于 2018-01-28 15:46:23
如果我理解你的意思,你可以试试这个:
$('.radio-button').on("click", function(event) {
var this_input = $(this);
if (this_input.attr('checked1') == '1') {
this_input.attr('checked1', '1')
} else {
this_input.attr('checked1', '2')
}
$('.radio-button').prop('checked', false);
if (this_input.attr('checked1') == '1') {
this_input.prop('checked', false);
this_input.attr('checked1', '2');
$('.box').hide(); // Hides button in second click
} else {
this_input.prop('checked', true);
this_input.attr('checked1', '1')
}
});下面是示例:http://jsfiddle.net/xjzutbr9/3/
https://stackoverflow.com/questions/48483881
复制相似问题