Use below code for if you checked checkbox than select box option is selected.(如果您选中了复选框而不是选择框选项,请使用以下代码。)
For example: HTML:(例如:HTML:)
<div>
<select id="newselect" name="newselect">
<option value="newoptionone">New Option One</option>
<option value="newoptiontwo">New Option Two</option>
<option value="nothing" selected="selected">Nothing</option>
</select>
</div>
<div>
<input id="newcheckbox" name="newcheckbox" type="checkbox" value="1"/>New Checkbox
</div>
Javascript:(Javascript:)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('input[type="checkbox"]').click(function(){
if($(this).prop("checked") == true){
// $("#newselect option:eq(1)").val("nothing");
$("#newselect").val($("#newselect option:eq(1)").val());
}
else if($(this).prop("checked") == false){
$("#newselect").val($("#newselect option:eq(2)").val());
}
});
});
</script>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…