0
我正在進行單位轉換項目,其中我將單位轉換爲KG => GRAM或KG => TON等。我必須設置驗證方式,例如一旦選擇單位進行轉換,例如(KG => GRAM),它不應該允許用戶從(GRAM => KG)轉換。單位轉換驗證雙向
這裏是我的代碼:
<select onchange="checkDuplicateUnitConversion(this,0,'to');" class="to-unit0" name="toUnit">
<option value="1">kilogram</option>
<option value="2">gram</option>
</select>
JS代碼
function checkDuplicateUnitConversion(element,row,type)
{
$("select").each(function(index){
});
switch(type)
{
case 'from':
$("select[name='fromUnit']").each(function(index){
if(this.value===$('.to-unit'+index).val()){
alert("Select Valid Units");
$('#addMoreUnitConversion').prop('disabled', true);
}
else{
$('#addMoreUnitConversion').prop('disabled', false);
}
});
break;
case 'to':
$("select[name='toUnit']").each(function(index){
if(this.value===$('.from-unit'+index).val()){
alert("Select Valid Units");
$('#addMoreUnitConversion').prop('disabled', true);
}
else{
$('#addMoreUnitConversion').prop('disabled', false);
}
});
break;
}
}
因此,你想要允許圖像中顯示什麼? – DelightedD0D
是的,我想如果他進入圖像 – glenmax
顯示反之亦然好,那麼下面應該爲你工作 – DelightedD0D