多線程的全選復(fù)選框
更新時(shí)間:2006年11月04日 00:00:00 作者:
復(fù)制代碼 代碼如下:
<style>
BODY {FONT-SIZE: 9pt;}
table {FONT-SIZE: 9pt;}
</style>
<input type=checkbox id=checkall onclick=check_all()><label for=checkall>全部選擇</label>
線程數(shù):<input type=text id=the_thread value=10 size=2 maxlength=2 style="height:15px; font-size:12px;padding:0px">
<br>
<table border=0>
<tr><td style="width:100px;over-flow:hidden"><span id=show></span></td>
<td style="width:400px;">
<table id=bar style="width:90%;height:10px;border:1px black solid;display:none"><tr>
<td id=bar1 bgcolor=skyblue style="width:0%"></td>
<td id=bar2 style="width:100%"></td>
</tr></table>
</td></tr>
<tr><td colspan=2><span id=result></span></td></tr>
</table>
<script language="JavaScript">
/*
This following code are designed and writen by Windy_sk <seasonx@163.net>
You can use it freely, but u must held all the copyright items!
*/
var total = 505;
var thread_num;
var pre_thread;
var thread = new Array();
var completed = 0;
var start_time = null;
for(i=0;i<total;i++)document.write("<input type=checkbox id=cbox>");
function init_para(){
thread_num = parseInt(the_thread.value);
if(isNaN(thread_num)) thread_num = 10;
pre_thread = Math.floor(total/thread_num);
result.innerText = "";
bar1.style.width = "0%";
bar2.style.width = "100%";
bar.style.display = "";
}
function check_all(){
checkall.disabled = true;
init_para();
for(var i=0;i<thread_num;i++){
thread[i]=[setInterval("thread["+i+"][1]<pre_thread?check_unit("+i+"*pre_thread + thread["+i+"][1]++):clearInterval(thread["+i+"][0])",1),0];
}
thread[i]=[setInterval("thread["+i+"][1]<total%thread_num?check_unit("+i+"*pre_thread + thread["+i+"][1]++):clearInterval(thread["+i+"][0])",1),0];
}
function check_unit(num){
if(completed==0)start_time=new Date;
cbox[num].checked=checkall.checked;
completed++;
var cur_rate = Math.round(completed*100/total);
show.innerText = completed + "/" + total + " : " + cur_rate + "%";
bar1.style.width = cur_rate + "%";
bar2.style.width = (100-cur_rate) + "%";
if(completed == total){
completed = 0
checkall.disabled = false;
result.innerText = "("+total+"單元/"+thread_num+"線程,總共耗時(shí):"+((new Date)-start_time)+" ms)";
}
}
</script>
下面是運(yùn)行效果
[Ctrl+A 全選 注:引入外部Js需再刷新一下頁(yè)面才能執(zhí)行]
相關(guān)文章
checkbox 多選框 聯(lián)動(dòng)實(shí)現(xiàn)代碼
對(duì)于checkbox 多選的聯(lián)動(dòng)效果,是個(gè)不錯(cuò)的思路,附代碼2008-10-10
鼠標(biāo)移動(dòng)到某個(gè)單元格上后,整個(gè)列都變色的實(shí)現(xiàn)方法
鼠標(biāo)移動(dòng)到某個(gè)單元格上后,整個(gè)列都變色的實(shí)現(xiàn)方法...2007-01-01
css+js實(shí)現(xiàn)select列表橫向排列效果代碼
真不錯(cuò)的select橫排效果代碼,推薦大家閱讀,這個(gè)思路真不錯(cuò),太感謝作者了2008-06-06

