答案 0 :(得分:0)
我会这样做:
<select class="form-control input-sm" name="current_tier" id="current_rank">
<option selected=""value="1">SilverI</option>
<option value="2"> Silver II</option>
<option value="3">Silver III</option>
<option value="4">Silver IV</option>
<option value="5">Silver Elite</option>
<option value="6">Silver Elite Master</option>
<option value="7">Gold Nova I</option>
<option value="8">Gold Nova II</option>
<option value="9">Gold Nova III</option>
<option value="10">Gold Nova Master</option>
<option value="11">Master Guardian I</option>
<option value="12">Master Guardian II</option>
<option value="13">Master Guardian Elite</option>
<option value="14">Distinguished Master Guardian</option>
<option value="15">Legendary Eagle</option>
<option value="16">Legendary Eagle Master</option>
<option value="17">Supreme Master First Class</option>
<option value="18">Global Elite</option>
</select>
<select class="form-control input-sm" name="future_rank" id="order_rank">
<option selected="" value="2">Silver II</option>
<option value="3">Silver III</option>
<option value="4">Silver IV</option>
<option value="5">Silver Elite</option>
<option value="6">Silver Elite Master</option>
<option value="7">Gold Nova I</option>
<option value="8">Gold Nova II</option>
<option value="9">Gold Nova III</option>
<option value="10">Gold Nova Master</option>
<option value="11">Master Guardian I</option>
<option value="12">Master Guardian II</option>
<option value="13">Master Guardian Elite</option>
<option value="14">Distinguished Master Guardian</option>
<option value="15">Legendary Eagle</option>
<option value="16">Legendary Eagle Master</option>
<option value="17">Supreme Master First Class</option>
<option value="18">Global Elite</option>
</select>
<p id="finalvalue">Final Value</p>
<button type="button" id="btnForChosing">Click Me!</button>
<script type="text/javascript">
var btn = document.getElementById("btnForChosing");
btn.onclick= function(){
var finalValue = document.getElementById("finalvalue");
var curRank = document.getElementById("current_rank");
var selectedCurRank= curRank.options[curRank.selectedIndex].value;
var orderRank= document.getElementById("order_rank");
var selectedOrderRank= orderRank.options[orderRank.selectedIndex].value;
if (selectedCurRank > selectedOrderRank)
finalValue.innerHTML = "error"
}
</script>
完成你的第一个案例的逻辑,因为我不遵守你在那里使用“21”的逻辑
答案 1 :(得分:0)
我不知道你如何得出'21',但这应该让你开始。第二次更改后,比较所选选项的索引。如果要计算差异的值,则需要对所选选项的值进行基本求和,并将其附加到输出而不是21。
编辑以将值分配给级别并计算第二个选项的更改差异。您可以将值调整为所需的数字。
$('#order_rank').on('change', function() {
$('#finalvalue').html('Final Value: ');
var current = +$('#current_rank option:selected').val();
var future = +$('#order_rank option:selected').val()
if (current <= future) {
var value = +future - current;
$('#finalvalue').append(value);
} else {
$('#finalvalue').append('ERROR');
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select class="form-control input-sm" name="current_tier" id="current_rank">
<option selected="" value="1">Silver I</option>
<option value="2">Silver II</option>
<option value="3">Silver III</option>
<option value="4">Silver IV</option>
<option value="5">Silver Elite</option>
<option value="6">Silver Elite Master</option>
<option value="7">Gold Nova I</option>
<option value="8">Gold Nova II</option>
<option value="9">Gold Nova III</option>
<option value="10">Gold Nova Master</option>
<option value="11">Master Guardian I</option>
<option value="12">Master Guardian II</option>
<option value="12">Master Guardian Elite</option>
<option value="14">Distinguished Master Guardian</option>
<option value="15">Legendary Eagle</option>
<option value="16">Legendary Eagle Master</option>
<option value="17">Supreme Master First Class</option>
<option value="18">Global Elite</option>
</select>
<select class="form-control input-sm" name="future_rank" id="order_rank">
<option selected="" value="2">Silver II</option>
<option value="3">Silver III</option>
<option value="4">Silver IV</option>
<option value="5">Silver Elite</option>
<option value="6">Silver Elite Master</option>
<option value="7">Gold Nova I</option>
<option value="8">Gold Nova II</option>
<option value="9">Gold Nova III</option>
<option value="10">Gold Nova Master</option>
<option value="11">Master Guardian I</option>
<option value="12">Master Guardian II</option>
<option value="13">Master Guardian Elite</option>
<option value="14">Distinguished Master Guardian</option>
<option value="15">Legendary Eagle</option>
<option value="16">Legendary Eagle Master</option>
<option value="17">Supreme Master First Class</option>
<option value="18">Global Elite</option>
</select>
<p id="finalvalue">Final Value</p>
答案 2 :(得分:0)
以下是解决方案
function setOutput(){
var current_rank = parseInt($('#current_rank').val()); /*Get current_rank value*/
var order_rank = parseInt($('#order_rank').val()); /*Get order_rank value*/
if (current_rank==order_rank) {
$('#finalvalue').html(current_rank+' == '+order_rank);
}else if(current_rank>order_rank){
$('#finalvalue').html(current_rank+' > '+order_rank);
}else{
$('#finalvalue').html(current_rank+' < '+order_rank);
}
}
$('#current_rank,#order_rank').change(function(){
setOutput();
});
setOutput();
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select class="form-control input-sm" name="current_tier" id="current_rank">
<option value="1">Silver I</option>
<option value="2">Silver II</option>
<option value="3">Silver III</option>
<option value="4">Silver IV</option>
<option value="5">Silver Elite</option>
<option value="6">Silver Elite Master</option>
<option value="7">Gold Nova I</option>
<option value="8">Gold Nova II</option>
<option value="9">Gold Nova III</option>
<option value="10">Gold Nova Master</option>
<option value="11">Master Guardian I</option>
<option value="12">Master Guardian II</option>
<option value="13">Master Guardian Elite</option>
<option value="14">Distinguished Master Guardian</option>
<option value="15">Legendary Eagle</option>
<option value="16">Legendary Eagle Master</option>
<option value="17">Supreme Master First Class</option>
<option value="18">Global Elite</option>
</select>
<select class="form-control input-sm" name="future_rank" id="order_rank">
<option value="2">Silver II</option>
<option value="3">Silver III</option>
<option value="4">Silver IV</option>
<option value="5">Silver Elite</option>
<option value="6">Silver Elite Master</option>
<option value="7">Gold Nova I</option>
<option value="8">Gold Nova II</option>
<option value="9">Gold Nova III</option>
<option value="10">Gold Nova Master</option>
<option value="11">Master Guardian I</option>
<option value="12">Master Guardian II</option>
<option value="13">Master Guardian Elite</option>
<option value="14">Distinguished Master Guardian</option>
<option value="15">Legendary Eagle</option>
<option value="16">Legendary Eagle Master</option>
<option value="17">Supreme Master First Class</option>
<option value="18">Global Elite</option>
</select>
<p id="finalvalue">Final Value</p>
&#13;
注意:现在您可以检查它们并获得实际结果。您可以从
更改条件setOutput()
功能