📄 checkbox_test.html
字号:
d.appendChild(edit);
d.appendChild(document.createTextNode(" | "));
del.appendChild(document.createTextNode("delete"));
d.appendChild(del);
d.style.width="80px";
d.style.lineHeight="20px";
d.style.color="blue";
// d.style.zIndex="-10";
// d.style.backgroundColor="green";
document.body.appendChild(d);
$(theid).onmouseover=function(){
currentDiv.style.backgroundColor = overCol;
this.style.display="";
//mouseOndeleteDiv=true;
}
/* $(theid).onclick=function(){
delSingle(currentDiv.parentNode,this,currentDiv);
}*/
//
$(theid).style.cursor="pointer";
}
if($(theid)){
$(theid).style.display="";
var l= getAbsoluteLeft(self) + self.offsetWidth - 80;
var t= getAbsoluteTop(self) + 5;
var scrollT = self.parentNode.scrollTop;//减去出现滚动条的高度;
var t= getAbsoluteTop(self) + 5 - scrollT;
//document.title = getAbsoluteLeft(self) +"|"+ getAbsoluteTop(self) +"|"+ self.offsetWidth +"|"+ self.offsetHeight + "t:"+t + "l:"+l;
$(theid).style.position="absolute";
$(theid).style.left = l+"px";
$(theid).style.top = t+"px";
}
}
function hideDelete(self){
var theid = "del_icon";
if( $(theid) ){
self.style.backgroundColor = self.childNodes[0].checked?checkedCol:emptyCol;
$(theid).style.display="none";
}
}
</script>
</HEAD>
<BODY>
<style>
.drag{position:absolute;width:600px; background-color:#f1f1f1;
/*filter:alpha(opacity=80);
-moz-opacity:0.80;
opacity:0.80;*/
filter:alpha(opacity=100);
-moz-opacity:1.0;
opacity:1.0;
}
.da{width:100%;background-color:gray;cursor:move;font-size:14px;vertical-align:middle;line-height:30px}
.max_min_btn{float:right;color:red;cursor:pointer;font-size:9pt;width:50px;line-height:30px;text-align:center;}
#list{border-top:2px ridge #9A9898;border-left:2px ridge #9A9898;border-bottom:1px solid #D4D0C8;border-right:1px solid #D4D0C8;background:white;width:578px;height:350px;margin:10px;overflow:auto}
.shadowBottom{margin-left:6px;height:5px;background:gray;font-size:0px;line-height:0px;filter:alpha(opacity=55);-moz-opacity:0.55;opacity:0.55;}
</style>
<pre>
本例是采用JSP + Ajax + 文本来演示多选、全选,添加、删除、更新checkbox多选框的效果。
本例充分展现了利用JavaScript控制HTML DOM以及利用XML http 传递数据,利用JSP操作文本的效果。
1,JavaScript 用来控制页面内容的现实与增删效果;
2,JSP作为后台,对文本进行读取、写入、更新等操作;
3,文本格式是用来存储数据的,数据编码UTF-8;<br>4, 本例子在win32,Red hat Linux 9下 jdk1.5,Tomcat 5.0,Apache 2.5下调试通过,同时兼容Firefox 1.0,Opera 8.0,IE6。
本例子的优点:
1,实时创建html对象,所见即所得的页面增删操作。显示速度加快,增加用户体验。
2,XML http传递数据是只是一个id或一个表单值,节省带宽。
3,本例子适合采用XML http方式,所以这个效果实用性强,可是JS/JSP代码都很简单。
4,有很多东西可以在其他项目中共用,并且解决了操作文本关于中文字符编码的问题。
(本例子在中文操作系统运行,所以选择了GBK编码,如果OS是英文的则需要另外处理,比如改编码为UTF-8,或者根据需要另外转换编码。)<br>5,有拖拽以及展开关闭的效果,用cookie记录了位置以及打开关闭状态,可以在某个项目里用。
6,有丰富的注释,适合初学者一起探讨。
缺点:
1,维护调试麻烦,为了这个效果是否值得这样做?如果采用普通的方式,嵌入一个iframe进来,会不会也可以。
2,代码没有更多地优化、简写,有些地方冗余。
3,交互设计方面没有好好地做,这里主要表示的是技术实现和交流。<br><br>在线说明文档 <a href="http://jiarry.blogchina.com/5599587.html">http://jiarry.blogchina.com/5599587.html</a><br>静态页面演示地址:<A href="http://jarryli.googlepages.com/checkbox_test.html">http://jarryli.googlepages.com/checkbox_test.html</A> (详细的说明,随后补充)<BR>源文件下载地址:<A href="http://jarryli.googlepages.com/checkbox.rar">http://jarryli.googlepages.com/checkbox.rar</A>
</pre><br>
另外之前做的<br>
PHP+Ajax 发帖程序实例:<a href="http://jiarry.blogchina.com/5555296.html">http://jiarry.blogchina.com/5555296.html</a> 源码下载:<a href="http://jarryli.googlepages.com/post_ajax.rar">http://jarryli.googlepages.com/post_ajax.rar</a><br>
JSP登录证码无刷新提示:<a href="http://jiarry.blogchina.com/5287654.html">http://jiarry.blogchina.com/5287654.html</a> 源码下载:<a href="http://jarryli.googlepages.com/imgValidate.rar">http://jarryli.googlepages.com/imgValidate.rar</a><br>
<br>
<div class="drag" rel="drag" id="siteMainDarg" style="left:10px;top:10px;" onMouseDown="dargit(this,event);">
<div class="da" ><span class="max_min_btn" id="max_min" style="background-color:#333"><font style="font-family:webdings">2</font>CLOSE</span> 拖拽区</div>
<div id="sitelistDiv" >
<form name="sitelist" onSubmit="return addSite(this);" style="border:1px groove blue;margin:0;padding:0;border-top:0;"><br clear="all">
http:// <INPUT TYPE="text" size="30" NAME="url" onmouseover="this.focus()"> <INPUT TYPE="button" NAME="add" value="添加网址至列表" onClick="addSite(this.form)">
<div id="list">
<div onMouseOver="showDelete(this);" onmouseout="hideDelete(this);" style="padding:5px;border-bottom:1px dashed gray"><input type=checkbox value="example1.com" name="url_chkbox" onClick="clickchk(this.form)">example1.com </div>
<div onMouseOver="showDelete(this);" onMouseOut="hideDelete(this);" style="padding:5px;border-bottom:1px dashed gray"><input type=checkbox value="example2.com" name="url_chkbox" onClick="clickchk(this.form)">example2.com </div>
</div>
<INPUT TYPE="button" NAME="check" value="全选" disabled onClick="checkall(this.form)"> <input type="button" value="反选" name="recheck" disabled onclick="reverseCheck(this.form)"> <INPUT TYPE="button" NAME="remove" disabled value="删除" onClick="del($('list'),this.form)"><br><br>
</form>
</div>
<div class="shadowBottom"> </div>
</div><br><br><br>
Cody by JarryLi@gmail.com;
<br>
CopyRight©Jarry,All right reserved!<br>
本例仅供个人参考,引用请保留版权信息。谢谢!
<br>
homepage:<a href="http://jiarry.126.com">jiarry.126.com</a><br>
Blog:<a href="http://jiarry.blogchina.com">http://jiarry.blogchina.com</a>
<script>
//页面加载时初始化
function init(l,f){
var list=l;
f.check.disabled=list.childNodes.length>1?false:true;
f.recheck.disabled=list.childNodes.length>1?false:true;
f.check.value=strAll;
f.remove.disabled=list.childNodes.length>1?false:true;
}
window.onload=function(){
init($("list"),document.sitelist);
}
///////
/////////////////
//cookie
//////////////
activeCookie = true;
if(document.cookie==null){
//alert("cookie没有开启!");
activeCookie = false;
}
function getCookie(name) {
if( !activeCookie ) return;
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
function setCookie(name , value)
{
if( !activeCookie ) return;
var expdate = new Date();
expdate.setTime(expdate.getTime() + (365*24*120));
document.cookie=""+ name + "=" + value +";expires="+ expdate.toGMTString();
}
var theLeft = getCookie("siteMainDargLeft")!=null ? getCookie("siteMainDargLeft") : 10;
var theTop = getCookie("siteMainDargTop")!=null ? getCookie("siteMainDargTop") : 10;
var closeOrOpen = "CLOSE";
var listDivDisplay = getCookie("sitelistDivDisplay")!=null ? getCookie("sitelistDivDisplay") : "";
$("siteMainDarg").style.top = theTop;
$("siteMainDarg").style.left = theLeft;
$("sitelistDiv").style.display = listDivDisplay;
$("max_min").childNodes[1].nodeValue = $("sitelistDiv").style.display=="none" ? "OPEN": "CLOSE";
$("max_min").childNodes[0].innerHTML = $("sitelistDiv").style.display=="none" ? "1" : "2";
//cookie end;
////////////////////////
var d_width = 550;
var d_height = 30;
var ey=0,ex=0,lx=0,ly=0,canDrg=false,thiso=null;//
var x, y,rw,rh;
var divs=document.getElementsByTagName("div");
for (var i=0;i<divs.length;i++){
if(divs[i].getAttribute("rel")=="drag"){
divs[i].onmousemove=function(){
thismove(this);//实时得到当前对象与鼠标的值以判断拖动及关闭区域;
}
}
}
function thismove(o){
//rw=parseInt(x)-parseInt(o.style.left);
rw = parseInt(x)-parseInt(getAbsoluteLeft(o));
//rh=parseInt(y)-parseInt(o.style.top);
rh = parseInt(y)-parseInt(getAbsoluteTop(o));
//rw = Math.abs(rw);
//rh = Math.abs(rh);
//document.title=rw+"=文本区域="+rh;
//if(rh<=d_height && rw>=d_width &&rh>0)document.title=rw+"||20*20||"+rh;//右上角20*20的关闭区域
//if(rh<=d_height && rw<d_width &&rh>0)document.title=rw+"||可选||"+rh;//绝对拖动条选择区域;
//o.releaseCapture();
}
function dargit(o,e){
thiso = o;
canDrg = true;
if(!document.all){
lx = e.clientX; ly = e.clientY;
}else{
lx = event.x; ly = event.y;
}
// if(document.all) thiso.setCapture();
try{//设置渐变色;
if(rh<=d_height && rw<d_width &&rh>0){//设定在拖动区域
if(document.all)thiso.filters.Alpha.opacity=80;
else thiso.style.MozOpacity=80/100;
}
}catch(e){
// alert(e.toString());
}
st(o);
}
document.onmousemove = function(e){
if(!document.all){ x = e.clientX; y = e.clientY; }else{ x = event.x; y = event.y; }
if(canDrg){
if(rh<=d_height && rw<d_width &&rh>0){//如果要设定拖动区域可以作判断
var ofsx = x - lx;
thiso.style.left = (parseInt(thiso.style.left) + ofsx) +"px";
lx = x;
var ofsy = y - ly;
thiso.style.top = (parseInt(thiso.style.top) + ofsy) +"px";
ly = y;
}else{
canDrg=false;
}
//window.status=thiso.style.left+"left:top"+thiso.style.top+" rh:rw"+rh+"+"+rw +" x:"+x+" y:"+y +" lx:"+lx+" ly:"+ly;
}
}
document.onmouseup=function(){
canDrg=false;//拖拽变量设为false
try{//设置渐变色;
if(document.all)thiso.filters.Alpha.opacity=100;
else thiso.style.MozOpacity=100;
}catch(e){
// alert(e.toString());
}
if(document.all && thiso != null){
//ie下,将清空捕获;
thiso.releaseCapture();
thiso = null;
}
}
function st(o){
if(rh <= d_height && rw >= d_width){
canDrg=false;
showHide($("sitelistDiv"));
}
}
function showHide(obj,self){
obj.style.display = obj.style.display=="none"?"":"none";
//$("del_icon").display="none";
var icon = "1";
var text = "OPEN";
if(obj.style.display==""){
icon = "2";
text = "CLOSE";
}
$("max_min").childNodes[0].innerHTML = icon;
$("max_min").childNodes[1].nodeValue = text;
}
//设定层的显示位置;
function setposition(obj){
// alert(window.document.body.scrollHeight);
// alert(window.document.body.scrollTop);
$("mask").style.height = window.document.body.scrollHeight;
var w = parseInt(obj.style.width);
var h = parseInt(obj.style.height);
obj.style.left=(window.document.body.offsetWidth-w)/2+"px";
//obj.style.left=(window.screen.width-w)/2+"px";
//alert(window.screen.height+"-"+h);
// alert((window.document.body.offsetHeight-h)+"/"+2+"+"+window.document.body.scrollTop)
//if(!document.all)h=h*4;
obj.style.top=(window.document.body.offsetHeight-h)/2+window.document.body.scrollTop+"px";
}
//获取随机颜色值;
function GetColor()
{
var r = Math.floor(Math.random() * 255).toString(16);
var g = Math.floor(Math.random() * 255).toString(16);
var b = Math.floor(Math.random() * 255).toString(16);
r = r.length == 1 ? "0" + r : r;
g = g.length == 1 ? "0" + g : g;
b = b.length == 1 ? "0" + b : b;
return "#" + r + g + b;
}
window.onunload = function(){
setCookie("siteMainDargLeft",getAbsoluteLeft( $("siteMainDarg") ) );
setCookie("siteMainDargTop",getAbsoluteTop( $("siteMainDarg") ) );
setCookie("sitelistDivDisplay",$("sitelistDiv").style.display );
}
</script>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -