我有这个单选按钮。当选中no时,必须禁用下一个顶级单选按钮并取消选中(此操作有效)。当用户单击yes时,应启用下两个单选按钮并单击。问题在于,通过单击,yes,,按钮仍然是不可点击的。我做错了什么。我的代码如下。感谢你的帮助!
$(document).ready(function() {
$(".blind-7").attr('disabled', true);
$(".blind-8").attr('disabled', true);
$(".nebel-3").css('opacity', '0.1');
$("form input:radio").change(function() {
if ($('#033b').is(':checked')) {
$(".blind-7, .blind-8").attr('disabled', true);
$(".blind-7").prop('checked', false);
$(".blind-8").prop('checked', false);
$(".nebel-3").css('opacity', '0.1');
}
else if ($('#033a').is(':checked')) {
$(".blind-7, .blind-8").attr('disabled', false);
$(".nebel-3").css('opacity', '1');
}
});
});.nebel {
color: black;
background: #F9CA83;
}
.nebel-3 {
color: black;
background: #F9CA83;
}<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<label class="nebel" for="033">click here</label>
<input id="033b" type="radio" name="question" value="0"checked> <label for="033b">no</label>
<input id="033a" type="radio" name="question" value="1"> <label for="033a">yes</label>
<label class="nebel-3" for="034">type</label>
<input id="034b" class="blind-8" type="radio" name="type" value="0" > <label for="034b">A</label>
<input id="034a" class="blind-7" type="radio" name="type" value="1"> <label for="034a">B</label><br />
<label class="nebel-3" for="035">time</label>
<input id="035b" class="blind-8" type="radio" name="time" value="0" > <label for="035b">acute</label>
<input id="035a" class="blind-7" type="radio" name="time" value="1"> <label for="035a">chronic</label>
发布于 2018-01-16 23:45:37
选择器中没有父form。
将$("form input:radio")更改为$("input:radio")。
$(document).ready(function() {
$(".blind-7").attr('disabled', true);
$(".blind-8").attr('disabled', true);
$(".nebel-3").css('opacity', '0.1');
$("input:radio").change(function() {
if ($('#033b').is(':checked'))
{
$(".blind-7, .blind-8").attr('disabled', true);
$(".blind-7").prop('checked', false);
$(".blind-8").prop('checked', false);
$(".nebel-3").css('opacity', '0.1');
}
else if ($('#033a').is(':checked'))
{
$(".blind-7, .blind-8").attr('disabled', false);
$(".nebel-3").css('opacity', '1');
}
});
});.nebel {
color: black;
background:#F9CA83;
}
.nebel-3 {
color: black;
background:#F9CA83;
}<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<label class="nebel" for="033">click here</label>
<input id="033b" type="radio" name="question" value="0"checked> <label for="033b">no</label>
<input id="033a" type="radio" name="question" value="1"> <label for="033a">yes</label>
<label class="nebel-3" for="034">preop_ad_type_a</label>
<input id="034b" class="blind-8" type="radio" name="type" value="0" > <label for="034b">A</label>
<input id="034a" class="blind-7" type="radio" name="type" value="1"> <label for="034a">B</label><br />
<label class="nebel-3" for="035">preop_ad_type_b</label>
<input id="035b" class="blind-8" type="radio" name="time" value="0" > <label for="035b">acute</label>
<input id="035a" class="blind-7" type="radio" name="time" value="1"> <label for="035a">chronic</label>
发布于 2018-01-16 23:42:55
只需将这个$("form input:radio")修改为这个$("input:radio"),因为您没有表单标记。
$(document).ready(function() {
$(".blind-7").attr('disabled', true);
$(".blind-8").attr('disabled', true);
$(".nebel-3").css('opacity', '0.1');
$("input:radio").change(function() {
if ($('#033b').is(':checked')) {
$(".blind-7, .blind-8").attr('disabled', true);
$(".blind-7").prop('checked', false);
$(".blind-8").prop('checked', false);
$(".nebel-3").css('opacity', '0.1');
}
else if ($('#033a').is(':checked')) {
$(".blind-7, .blind-8").attr('disabled', false);
$(".nebel-3").css('opacity', '1');
}
});
});.nebel {
color: black;
background: #F9CA83;
}
.nebel-3 {
color: black;
background: #F9CA83;
}<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>DOM Example</title>
</head>
<body>
<label class="nebel" for="033">click here</label>
<input id="033b" type="radio" name="question" value="0"checked> <label for="033b">no</label>
<input id="033a" type="radio" name="question" value="1"> <label for="033a">yes</label>
<label class="nebel-3" for="034">preop_ad_type_a</label>
<input id="034b" class="blind-8" type="radio" name="type" value="0" > <label for="034b">A</label>
<input id="034a" class="blind-7" type="radio" name="type" value="1"> <label for="034a">B</label><br />
<label class="nebel-3" for="035">preop_ad_type_b</label>
<input id="035b" class="blind-8" type="radio" name="time" value="0" > <label for="035b">acute</label>
<input id="035a" class="blind-7" type="radio" name="time" value="1"> <label for="035a">chronic</label>
</body>
</html>
发布于 2018-01-16 23:44:51
行$("form input:radio").change试图将更改侦听器附加到表单内部的类型无线电输入。
这不起作用,因为你的单选按钮周围没有<form>标签。如果您添加这样的<form>标记,它就会工作:
<form>
<label class="nebel" for="033">click here</label>
<input id="033b" type="radio" name="question" value="0"checked> <label for="033b">no</label>
<input id="033a" type="radio" name="question" value="1"> <label for="033a">yes</label>
<label class="nebel-3" for="034">preop_ad_type_a</label>
<input id="034b" class="blind-8" type="radio" name="type" value="0" > <label for="034b">A</label>
<input id="034a" class="blind-7" type="radio" name="type" value="1"> <label for="034a">B</label><br />
<label class="nebel-3" for="035">preop_ad_type_b</label>
<input id="035b" class="blind-8" type="radio" name="time" value="0" > <label for="035b">acute</label>
<input id="035a" class="blind-7" type="radio" name="time" value="1"> <label for="035a">chronic</label>
</form>`或者,您可以更新要附加更改侦听器以读取:$("input:radio").change的行。
这两种方法都应该有效。
https://stackoverflow.com/questions/48291502
复制相似问题