如果我检查名称为“ most1”的单选按钮具有相同的值,如何禁用名称为“ least1”的单选按钮
<form action="{{route('questionnaire.action')}}" name="QuestionnaireForm" method="post" id="questionnaireEnglishForm">
<input type="radio" name="most1" value="Trusting & believing in others">
<input type="radio" name="least1" value="Trusting & believing in others">
<input type="radio" name="most1" value="Satisfied, easy to please">
<input type="radio" name="least1" value="Satisfied, easy to please">
<input type="radio" name="most1" value="Clear">
<input type="radio" name="least1" value="Clear">
<input type="radio" name="most1" value="Calm & Peaceful">
<input type="radio" name="least1" value="Calm & Peaceful">
</form>
答案 0 :(得分:2)
在Jquery中
[1] 您可以将change
事件用于most1
[2] 使用.filter()
按值过滤least1
[3] 使用.prop('disabled' , true/false)
打开/关闭禁用的属性
[4] 如果已选中.prop('checked' , false)
,则可能需要least1
取消选中
$('input[name="most1"]').on('change' , function(){
var GetValue = $(this).val();
$('[name="least1"]').prop('disabled' , false).filter(function(){
return $(this).val() == GetValue;
}).prop('disabled' , true).prop('checked' , false);
});
var i = 12;
console.log('[name="least' + i + '"]');
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form action="{{route('questionnaire.action')}}" name="QuestionnaireForm" method="post" id="questionnaireEnglishForm">
<input type="radio" name="most1" value="Trusting & believing in others">
<input type="radio" name="least1" value="Trusting & believing in others">
<input type="radio" name="most1" value="Satisfied, easy to please">
<input type="radio" name="least1" value="Satisfied, easy to please">
<input type="radio" name="most1" value="Clear">
<input type="radio" name="least1" value="Clear">
<input type="radio" name="most1" value="Calm & Peaceful">
<input type="radio" name="least1" value="Calm & Peaceful">
</form>
要在javascript $('[name="least' + i + '"]')
中串联字符串,您可以在上方看到代码段