1 回答
TA贡献1858条经验 获得超8个赞
试试这个,也看看我的评论
$(function () {
var sec = $('.security');
sec.change(function () {
let currentSelect=$(this).find('option:selected').val(); // Your code use sec.find() which is wrong since it picks the first selected option of first select.
$('.security option').show();
$('.security option[value="' + currentSelect + '"]').hide(); // This is shorter code.
}).change();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="col-sm-6 form-group">
<label for="security-question-1"><span class="trn">Security Question</span> 1 *</label>
<select class="form-control security" id="security-question-1">
<option class="trn" disabled selected value>select a question</option>
<option class="trn" value="q1">What is the name of your first school?</option>
<option class="trn" value="q2">What is your favorite movie?</option>
<option class="trn" value="q3"> What is your mother's maiden name?</option>
<option class="trn" value="q4">What street did you grow up on?</option>
</select>
</div>
<div class="col-sm-6 form-group">
<label for="security-question-2"><span class="trn">Security Question</span> 2 *</label>
<select class="form-control security" id="security-question-2">
<option class="trn" disabled selected value>select a question</option>
<option class="trn" value="q1">What is the name of your first school?</option>
<option class="trn" value="q2">What is your favorite movie?</option>
<option class="trn" value="q3"> What is your mother's maiden name?</option>
<option class="trn" value="q4">What street did you grow up on?</option>
</select>
</div>
- 1 回答
- 0 关注
- 89 浏览
添加回答
举报