【发布时间】:2019-03-09 18:53:16
【问题描述】:
所以,我有 4 个复选框:
- 加热
- 交流
- 冷链
- 其他
条件是,您可以同时检查三个:加热、交流和冷链。但是,当您选中“其他”时,这三个将被取消选中。当您再次选中三个中的任何一个时,其他复选框将被取消选中。
勾选Others时,会出现“请说明”的输入文字。
总之,在其他人中寻找解决方案 - [价值]
这是我的小提琴
$(document).ready(displayCheckbox);
CountSelectedCB = [];
function displayCheckbox() {
$("input:checkbox").change(function() {
selectedCB = [];
notSelectedCB = [];
CountSelectedCB.length = 0;
$("input:checkbox").each(function() {
if ($(this).is(":checked")) {
CountSelectedCB.push($(this).attr("value"));
}
});
$('input[name=solutions]').val(CountSelectedCB).blur();
});
}
$(document).ready(displayRadiobox);
CountSelectedRB = [];
function displayRadiobox() {
$("input:radio").change(function() {
selectedRB = [];
notSelectedRB = [];
CountSelectedRB.length = 0;
$("input:radio").each(function() {
if ($(this).is(":checked")) {
CountSelectedRB.push($(this).attr("value"));
}
});
$('input[name=existing]').val(CountSelectedRB).blur();
});
}
$('#solutions, #existing').bind('keyup blur', function() {
$('#summary').val('You are looking for solutions in ' + $('#solutions').val() + (' \n') + 'Are you using an existing customer? ' + $('#existing').val());
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div> Looking for a solutions in:<br>
<input type="checkbox" value="Heating">Heating<br>
<input type="checkbox" value="Ac">AC<br>
<input type="checkbox" value="Cold Chain">Cold Chain<br>
<input type="checkbox" value="Others">Others<br>
</div>
<input name="specify" type="text" id="specify" style="display: none">
<input name="solutions" type="text" id="solutions">
<div><br>Are you an exisiting customer?<br>
<input type="radio" value="Yes" name="radio">Yes<br>
<input type="radio" value="No" name="radio">No
</div>
<input name="existing" type="text" id="existing">
<br><br> Summary:
<br>
<textarea type='text' id="summary"></textarea>
【问题讨论】:
-
你有什么尝试取消选中其他的?
标签: javascript jquery checkbox