编写一个函数,计算三个不同数字的大小,按从小到大顺序打印 穷举法
<body>
<input type="text" id="txt1">
<input type="text" id="txt2">
<input type="text" id="txt3">
<input type="button" id="btn" value="比较">
<input type="text" readonly id="res">
</body>
<script>
var txt1 = document.getElementById("txt1");
var txt2 = document.getElementById("txt2");
var txt3 = document.getElementById("txt3");
var btn = document.getElementById("btn");
var res = document.getElementById("res");
btn.onclick = function(){
var n1 = txt1.value * 1;
var n2 = txt2.value - 0;
var n3 = Number(txt3.value);
var str = "";
if(n1 > n2 && n1 > n3){
if(n2 > n3){
str = "" + n1 + n2 + n3;
}else{
str = "" + n1 + n3 + n2;
}
}else if(n2 > n1 && n2 > n3){
if(n1 > n3){
str = "" + n2 + n1 + n3;
}else{
str = "" + n2 + n3 + n1;
}
}else if(n3 > n1 && n3 > n2){
if(n1 > n2){
str = "" + n3 + n1 + n2;
}else{
str = "" + n3 + n2 + n1;
}
}
res.value = str;
}
</script>