这样最好用数组,然后用数组的排序 sort(),再取第一个和最后一个值就OK了!
解决方案 »
- EXT4.0 Combox组件 proxy传值问题
- <web:binding 什么意思
- 解决一个WEBPART中的JAVASCRIPT展现问题,现金50元酬谢,绝不食言,有意者请留QQ或者MSN!
- 我想控制权限,有权限的能看到,怎么写啊?
- 知道 梅花雪 的qq喽~~~~~~~~~~~~~~~~~~~~~~
- 我觉得window.alert,prompt待方法的显示效果不好,我想改为自己的方法,试问window.alert,prompt方法可以重载的吗?
- 如何得到弹出对话框的父窗口
- 如何让用window.open()打开的窗口居中
- 怎样判断焦点(focus)是否在一个控件上?
- 帮帮忙,javascript中调用的activeX控件怎么做啊?急救!!
- 问大家一个有关js的小问题?
- 我放在页面上用于等侍的层
<input id="t2" type="text" value="8">
<input id="t3" type="text" value="6">
<input type="button" value="look" onclick="look();">
<script>
function look(){
var list = new Array(3);
list[0] = document.getElementById("t1").value;
list[1] = document.getElementById("t2").value;
list[2] = document.getElementById("t3").value;
list.sort();
alert("min:"+list[0]+",max:"+list[list.length-1]);
}
</script>
<input id="t2" type="text" value="8">
<input id="t3" type="text" value="6">
<input type="button" value="look" onclick="look();">
<script>
function look()
{
var list = new Array(3);
list[0] = document.getElementById("t1").value;
list[1] = document.getElementById("t2").value;
list[2] = document.getElementById("t3").value;
//list.sort();
//alert("min:"+list[0]+",max:"+list[list.length-1]);
alert(Math.max.apply(null, list));
alert(Math.min.apply(null, list));
}
</script>
<input id="t2" type="text" value="8">
<input id="t3" type="text" value="6">
<input type="button" value="look" onclick="look();">
<script>
function look()
{
alert(Math.max.call(null
,document.getElementById("t1").value
,document.getElementById("t2").value
,document.getElementById("t3").value
));
alert(Math.min.call(null
,document.getElementById("t1").value
,document.getElementById("t2").value
,document.getElementById("t3").value
));
}
</script>
后者比前者效率高的依据在哪里?
if(!nParam)var nParam=1;
switch(nParam){
case 2: return oAr.reverse();
case 3: return oAr.sort(function(a,b){return a-b;});
case 4: return oAr.sort(function(a,b){return b-a;});
default: return oAr.sort();
}
} // shawl.qiu script
Array.sort() 对于乱序有数组而言,操作的次数要多于单循环的操作数,所以效率不如上者。第二个回复用call我算是画蛇添足了。
Array.sort() 对于乱序有数组而言,操作的次数要多于单循环的操作数,所以效率不如上者。max是O(n)级的,而排序算法至少是O(nlogn)级的。