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