0
有谁知道如何比较jQuery中的选定值?将选定的选项值与其他变量进行比较
我有一个最低需求变量,假设它的$CD
(当前度数变量),然后我需要将它与列表框中的选定值进行比较。变量A不能比其他选择的索引变量。
HTML:
<select class="form-control" name="currentDegree" id="currentDegree">
<option value="Junior High School">Junior High School</option>
<option value="Senior High School">Senior High School</option>
<option value="Diploma">Diploma</option>
<option value="Bachelor Degree">Bachelor Degree</option>
<option value="Master">Master</option>
<option value="Doctor">Doctor</option>
</select>
JS:
<script>
var currentDegree = $('#degreeofCollegeoption').val(); // selected option
var minimumDegree = 3; // i set it for bachelor degree, actuallyit shuld <'<?php echo varX; ?>'> from admin
var CD; // dinamic variable (with selected condition)
functionCheckDegree(){
// Declare the var cd with value, so it will easilly compared
if (currentDegree == 'Junior High School') {
mp = 0;
} else if (currentDegree == 'Senior High School') {
mp = 1;
}
else if (currentDegree == 'Diploma') {
mp = 2;
}
else if (currentDegree == 'Bachelor Degree') {
mp = 3;
}
else if (currentDegree == 'Master') {
mp = 4;
}
else (currentDegree == 'Doctor') {
mp = 5;
}
};
// Compare the currentDegree variable with External variable
if (mp < minimumDegree) {
alert(" Current degree is less than Our minimum requirement !");
}
</script>
我用在提交onclick="CheckDegree()"
,但它似乎并没有做任何事情。
感谢队友@scrowler – user3279136