以下程序接受4个输入,如果所有4个输入都是数字,程序应按顺序排序数字,否则(如果输入是字母表),它应显示无效输入。
目前它显示无效条目,仅输入数字,无论我输入什么
有人可以帮忙吗?
<!DOCTYPE html>
<html>
<body>
<input id="num1" type="number">
<input id="num2" type="number">
<input id="num3" type="number">
<input id="num4" type="number">
<button type="button" onclick= "Val()">Submit</button>
<p id="sort">
SORTED NUMBERS ARE
</p>
<script>
function Val()
{
int a, b, c, d, e;
var text;
a = document.getElementById ("num1").value;
b = document.getElementById ("num2").value;
c = document.getElementById ("num3").value;
d = document.getElementById ("num4").value;
if (isNaN(a)||isNaN(b)||isNaN(c)||isNaN(d))
{
text = "Invalid Entry";
document.getElementById("sort").innerHTML = text;
window.alert ("ENTER ONLY NUMBERS");
//return false;
}
else
{
e = [a,b,c,d];
e.sort ();
document.getElementById("sort").innerHTML = e;
window.alert ("SORTED");
}
}
</script>
</body>
</html>
答案 0 :(得分:0)