Home  >  Article  >  Web Front-end  >  javascript 简练的几个函数_javascript技巧

javascript 简练的几个函数_javascript技巧

WBOY
WBOYOriginal
2016-05-16 18:47:28936browse

复制代码 代码如下:

//日期类
function myDate(time){
var d = new Date(time);
this.y=d.getFullYear();
this.m=d.getMonth();
this.d=d.getDate();
this.h=d.getHours();
this.m=d.getMinutes();
this.s=d.getSeconds();
}
//创建DOM
function createDOM(e,p){
var el=document.createElement(e);
if(!p)
p=document.body;
p.appendChild(el);
return el;
}
//为dom添加事件监听
function addEvent(el,event,fn){
el.addEventListener?el.addEventListener(event,fn,false):el.attachEvent("on"+event,fn);
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn