链接类

VML

按钮类

标题类

表单类

表格类

菜单类

窗口类

对象类

滚动条

键盘类

框架类

例子类

模拟类

日期类

色彩类

鼠标类

数学类

图片类

文字类

下拉框

样式类

游戏类

状态栏

资料类

字幕类

其它类

 ·禁用输入法
 ·Tab顺序
 ·radio值
 ·file框模拟新解
 ·检验上传图片
 ·单选框验证
 ·Checkbox控制...
 ·检测中英文字符长度
 ·禁止自动完成
 ·禁止自动完成
您当前位置:好素材首页 -> 网页特效 -> 表单类
查看信息

鼠标框选多选框
好素材网 www.HaoSc.com 02月22日 11:49

[查看演示]  源码如下
----------------------------------------------------------
<html>
<head>
<SCRIPT language=JavaScript>
/*--------------------------------------------
本程式为鼠标框选 多选框 辅助 帮手,其中还有不足.
1. 不能将多选框单独放到body标签中.
2. 多选框使用名子为ck+自然数, 如ck1.
3. 就先这么多吧,可能还有...........
制作者:八神奄 QQ:13730452
--------------------------------------------*/
var x0;
var y0;
var selectenable=0;

function initChkBox(obj){
var coll=document.forms["form1"].tags("input");
for (i=0;i<coll.length;i++){
if (coll.item(i).name.substr(0,2)=="ck") {
var offsetTop = 0;
var offsetLeft = 0;
var objP = coll.item(i);
while (objP.tagName!="BODY"&&objP){
offsetTop += objP.offsetTop;
offsetLeft += objP.offsetLeft;
objP = objP.offsetParent;
}
coll.item(i).X=offsetLeft+10;
coll.item(i).Y=offsetTop+10;
//alert(coll.item(i).X+","+coll.item(i).Y+","+coll.item(i).offsetHeight);
}
}
}

function initselect() {
if (window.event.srcElement.tagName=="BODY") {
window.event.returnValue = true;
return;
}

x0=document.body.scrollLeft+event.clientX;
y0=document.body.scrollTop+event.clientY;
selectarea.setCapture();
selectenable=1;
}
function startselect() {
if (selectenable==1) {
selectarea.style.visibility='visible';

if(document.body.scrollLeft+event.clientX-x0>0) {
selectarea.style.left=x0;
selectarea.style.width=document.body.scrollLeft+event.clientX-x0;
}
else{
selectarea.style.left=document.body.scrollLeft+event.clientX;
selectarea.style.width=x0-(document.body.scrollLeft+event.clientX);
}
if (document.body.scrollTop+event.clientY-y0>0) {
selectarea.style.top=y0;
selectarea.style.height=document.body.scrollTop+event.clientY-y0;
}
else{
selectarea.style.top=document.body.scrollTop+event.clientY;
selectarea.style.height=y0-(document.body.scrollTop+event.clientY);
}
}
window.event.returnValue = true;
}

function endselect() {
if (selectenable==0) return false;
selectenable=0;
selectarea.style.visibility='hidden';
selectarea.releaseCapture();
document.onmousemove=null;
var coll=document.forms["form1"].tags("input");
for (i=0;i<coll.length;i++){
if (coll.item(i).name.substr(0,2)=="ck") {
/* if (((coll.item(i).X>selectarea.offsetLeft)&&(coll.item(i).X<selectarea.offsetLeft+selectarea.offsetWidth))&&((coll.item(i).Y>selectarea.offsetTop)&&(coll.item(i).Y<selectarea.offsetTop+selectarea.offsetHeight))){
coll.item(i).checked=!coll.item(i).checked;}
*/
if (coll.item(i).X>selectarea.offsetLeft)
if (coll.item(i).X<selectarea.offsetLeft+selectarea.offsetWidth)
if (coll.item(i).Y>selectarea.offsetTop)
if (coll.item(i).Y<selectarea.offsetTop+selectarea.offsetHeight)
coll.item(i).checked=!coll.item(i).checked
}
}
selectarea.style.pixelHeight=0;
selectarea.style.pixelWidth=0;
}

/*function hideselect() {
//if (document.body.scrollLeft+event.clientX==x0 && document.body.scrollTop+event.clientY==y0 && event.srcElement!=selectarea)
selectarea.style.visibility='hidden';
}*/
function checkAll(){
document.form1.allsel.checked=false;
var coll=document.forms["form1"].tags("input");
for (i=0;i<coll.length;i++){
if (coll.item(i).name.substr(0,2)=="ck") {
coll.item(i).checked=false;
}
}
}
function change(v){
var f = document.forms["form1"];
for (i=0;i<f.elements.length;i++)
if (f.elements[i].name.substr(0,2)=="ck") f.elements[i].checked = v;
}
</SCRIPT>

<script language="JavaScript" type="text/JavaScript">
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
</script>
<title>您想要的-www.51windows.Net</title>
</head>
<body onmousedown="initselect()" onmousemove=startselect() onmouseup=endselect() onselectstart="return false;" onLoad=initChkBox()>
<table width="100%" height="100%" cellpadding="0" cellspacing="0" bgcolor="efefef">
<tr><td>
<DIV id=selectarea style="border:1px dashed black;HEIGHT: 42px; LEFT: 0px; POSITION: absolute; TOP: 0px; VISIBILITY: hidden; WIDTH: 67px; Z-INDEX: 10">
<img src="null" height="1" width="1"> </DIV>
<div id="Layer1" style="position:absolute; left:256px; top:39px; width:203px; height:401px; z-index:1">
<form name="form1" action="">
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#339999">
<tr bgcolor="#FFFFFF">
<td width="13%"><input type="checkbox" name="ck1" value="checkbox"></td>
<td width="87%">&nbsp;</td>
</tr>
<tr bgcolor="#FFFFFF">
<td><input type="checkbox" name="ck2" value="checkbox"></td>
<td>&nbsp;</td>
</tr>
<tr bgcolor="#FFFFFF">
<td><input type="checkbox" name="ck3" value="checkbox"></td>
<td>&nbsp;</td>
</tr>
<tr bgcolor="#FFFFFF">
<td><input type="checkbox" name="ck4" value="checkbox"></td>
<td>&nbsp;</td>
</tr>
<tr bgcolor="#FFFFFF">
<td><input type="checkbox" name="ck5" value="checkbox"></td>
<td>&nbsp;</td>
</tr>
<tr bgcolor="#FFFFFF">
<td><input type="checkbox" name="ck6" value="checkbox"></td>
<td>&nbsp;</td>
</tr>
<tr bgcolor="#FFFFFF">
<td><input type="checkbox" name="ck7" value="checkbox"></td>
<td>&nbsp;</td>
</tr>
<tr bgcolor="#FFFFFF">
<td><input type="checkbox" name="ck8" value="checkbox"></td>
<td>&nbsp;</td>
</tr>
<tr bgcolor="#FFFFFF">
<td><input type="checkbox" name="ck9" value="checkbox"></td>
<td>&nbsp;</td>
</tr>
<tr bgcolor="#FFFFFF">
<td><input type="checkbox" name="ck10" value="checkbox"></td>
<td>&nbsp;</td>
</tr>
<tr bgcolor="#FFFFFF">
<td><input type="checkbox" name="ck11" value="checkbox"></td>
<td>&nbsp;</td>
</tr>
<tr bgcolor="#FFFFFF">
<td><input type="checkbox" name="ck12" value="checkbox"></td>
<td>&nbsp;</td>
</tr>
<tr bgcolor="#FFFFFF">
<td><input type="checkbox" name="ck13" value="checkbox"></td>
<td>&nbsp;</td>
</tr>
<tr bgcolor="#FFFFFF">
<td><input type="checkbox" name="ck14" value="checkbox"></td>
<td>&nbsp;</td>
</tr>
<tr bgcolor="#FFFFFF">
<td><input type="checkbox" name="ck15" value="checkbox"></td>
<td>&nbsp;</td>
</tr>
<tr bgcolor="#FFFFFF">
<td><input type="checkbox" name="ck16" value="checkbox"></td>
<td>&nbsp;</td>
</tr>
<tr bgcolor="#FFFFFF">
<td><input type="checkbox" name="ck17" value="checkbox"></td>
<td>&nbsp;</td>
</tr>
<tr bgcolor="#FFFFFF">
<td><input type="checkbox" name="ck18" value="checkbox"></td>
<td>&nbsp;</td>
</tr>
<tr bgcolor="#FFFFFF">
<td><input type="checkbox" name="ck19" value="checkbox"></td>
<td>&nbsp;</td>
</tr>
<tr bgcolor="#FFFFFF">
<td><input type="checkbox" name="ck20" value="checkbox"></td>
<td>&nbsp;</td>
</tr>
<tr bgcolor="#FFFFFF">
<td><input type="checkbox" name="ck21" value="checkbox"></td>
<td>&nbsp;</td>
</tr>
</table>
<input type="checkbox" name="allsel" value="checkbox" onclick="change(this.checked)">
<button onClick="checkAll()">清空</button>
</form>
</div>
</td></tr>
</table>
</body>
</html>

<div style="position: absolute; top: 10; right: 10; width: 148; height: 18;cursor:hand">
<input type="button" name="Button" value="查看源代码" onClick= 'window.location = "view-source:" + window.location.href'></div>


此信息共 1 页 [1]