Posts Tagged ‘js’

attachEvent()/addEventListener()方法

Posted in 默认分类 on 二月 5th, 2009 by admin – Be the first to comment

用attachEvent()/addEventListener()方法添加触发事件2007-05-12 15:11在近来的工作中,用到了attachEvent方法,该方法可以为某一事件附加其它的处理事件,有时候可能比较有用,这里将其基本用法总结一下。

其语法可以查看《DHTML手册》,里面有详细的说明,这里贴一个例子,该例子来自互联网:

document.getElementById(“btn”).onclick = method1;
document.getElementById(“btn”).onclick = method2;
document.getElementById(“btn”).onclick = method3;
如果这样写,那么将会只有medhot3被执行

写成这样:
var btn1Obj = document.getElementById(“btn1″);
//object.attachEvent(event,function);
btn1Obj.attachEvent(“onclick”,method1);
btn1Obj.attachEvent(“onclick”,method2);
btn1Obj.attachEvent(“onclick”,method3);
执行顺序为method3->method2->method1

如果是Mozilla系列,并不支持该方法,需要用到addEventListener
var btn1Obj = document.getElementById(“btn1″);
//element.addEventListener(type,listener,useCapture);
btn1Obj.addEventListener(“click”,method1,false);
btn1Obj.addEventListener(“click”,method2,false);
btn1Obj.addEventListener(“click”,method3,false);
执行顺序为method1->method2->method3

JavaScript中confirm的用法

Posted in 前端技术 on 十二月 19th, 2008 by admin – Be the first to comment

configrm 用于删除或者其他时提示返回 t , f

	if(window.confirm("确定删除吗?")){
		$.get("../member/action.php?act=del", { snapID: id},
		   function(data){
				if(data==1){
					alert('success');
					removeNode1(obj.parentNode.parentNode);
				}else{
					alert('error');
				}
		   }
		);
	}
	return false;

动态给ifram添加内容,兼容ie和FF

Posted in 前端技术 on 十二月 12th, 2008 by admin – Be the first to comment

第一次知道,还可以这样写

<iframe width=’100%’ height=’100%’ name=’boot’ id=’boot’ src=” frameborder=’0′ scrolling=’no’></iframe>
<SCRIPT   LANGUAGE=”JavaScript”>  
<!–  
var iframe = window.frames['boot'];
iframe.document.open();
iframe.document.write(‘<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>\n’);
iframe.document.write(‘<html xmlns=”http://www.w3.org/1999/xhtml”>\n’);
iframe.document.write(‘<head>\n’);
iframe.document.write(‘<meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″ />\n’);
iframe.document.write(‘</head>\n’);
iframe.document.write(‘<body>\n’);
iframe.document.write(‘请等待…’);
iframe.document.write(‘</body>\n’);
iframe.document.write(‘</html>\n’);
iframe.document.close();
//–>  
</SCRIPT>

javascript与php类型转换

Posted in 前端技术, 后端技术 on 十一月 27th, 2008 by admin – Be the first to comment

1. 字符串转换为整型
//php
intval(); //php
floatval();//php浮点
strval();

//javascript
toString(); //转化为整型
parseInt(); //js 转化为整型
parseFloat(); //转化为浮点
Number(); //js, 这个会自动转

js调用Windows自带的配色控件

Posted in 默认分类 on 十一月 17th, 2008 by admin – Be the first to comment

仅适合于iE浏览器 window平台




各种图片与内容展示(lightbox)实现

Posted in 前端技术 on 十一月 13th, 2008 by admin – Be the first to comment

Thickbox – 基于 jQuery,支持 AJAX,轻量级的而且比较高效。可以在 lightbox 中使用图片或 HTML。大小约为 40k,目前还可作为 WordPress 的插件使用。

GreyBox – 创建 iframe 的弹出界面,可使用图片、HTML 及 URL,大小约为 20k。

GreyBox Redux – 基于 jQuery,比 GreyBox 更轻。

Lightbox v2.0 – 最初是为了显示图片设计的,使用了 prototype 和 sciptaculous,所以有些沉重,但对于图片来说很好用。

Lightbox with moo.fx – 基于 prototype,但只能用于图片。

Lightbox Gone Wild
– modal 模式窗口的 lightbox,可使用 html、表单及图片,也是基于 prototype 的,所以有一些 heavy。

Multi-faceted LIghtbox – 又一个基于 prototype 的,不过这个为各种可用于 lightbox 的数据类型提供了选项。

Leightbox – 和 Lightbox Gone Wild 很相似,只是 Leightbox 以 html 方式存放内容,所以可以被搜索引擎索引到。

xilinus – 使用简单,基于 prototype,很容易定制,可使用多种内容选项。

Lightbox Plus – 可以自动根据窗口的大小缩放图片。

Suckerfish Hover Lighbox – 和传统的 lightbox 不一样,它在打开 lightbox 的时候,还可以点击访问页面上的其它元素。

Litebox – 这是 Lightbox 的另一个版本,代码量减少了,使用了 moo.fx 和 prototype-lite,如果页面需要减肥的话,可以选择这个。

LITBox – 使用类写的 lightbox,所以可以创建多个对象实例,并且单独进行控制。基于 Thickbox。

基于jquery图片轮播广告

Posted in 前端技术 on 十月 31st, 2008 by admin – Be the first to comment

1. 需要引用 jquery库


2. 样式表

body{ padding:0px; margin:0px; }
#Carousel_Frame img{border:0;}
#Carousel_Frame{width: 450px; height:332px; text-align:left; overflow:hidden; border:0px solid #000; position:absolute; }
#Carousel_list{ width: 450px; height:332px; } /* 图片大小 */
#Carousel_list a{ display: block;}
#Carousel_Thumbnails { width: 450px;  HEIGHT: 56px;  position:absolute; z-index:2; top:270px; left:10px;}
#Carousel_Thumbnails ul{ filter: Alpha(Opacity=30); opacity: 0.8; padding:0px; margin:0px;}
#Carousel_Thumbnails ul li { float: left;  width: 50px;  position:relative; CURSOR: pointer;  HEIGHT: 50px;  BORDER: 3px solid #fff; margin-right:3px;}
#Carousel_Thumbnails ul li img{ width:50px; height:50px;}