随笔分类 -  JavaScript常用函数收录

收录JS常用函数
摘要:function selectFrom(iFirstValue,iLastValue){ var iChoices=iLastValue-iFirstValue+1; return Math.floor(Math.random()*iChoices+iFirstValue); } 阅读全文
posted @ 2012-03-09 11:53 猪弟 阅读(295) 评论(0) 推荐(0)
摘要:function: function getNextElement(node){ if(node.nodeType==1){ return node; } if(node.nextSibling){ return getNextElement(node.nextSibling); } return null; }实例代码:<!DOCTYPE html PUBLIC "-//W3C//DTD HTML... 阅读全文
posted @ 2012-02-20 22:47 猪弟 阅读(305) 评论(0) 推荐(0)
摘要:function insertAfter(newElement,targetElement){ var parent=targetElement.parentNode; if(parent.lastChild==targetElement){ parent.appendChild(newElement); }else{ parent.insertBefore(newElement,targetElement.nextSibling) } }相对于insertBefore()编写的i... 阅读全文
posted @ 2012-02-15 17:03 猪弟 阅读(257) 评论(0) 推荐(0)
摘要:function addLoadEvent(func){ var oldonload=window.onload; if(typeof window.onload!='function'){ window.onload=func; }else{ window.onload=function(){ oldonload(); func(); } } }注意调用的时候:addLoadEvent(func);... 阅读全文
posted @ 2012-02-14 22:15 猪弟 阅读(215) 评论(0) 推荐(0)
摘要:function addClass(element,value){ if(!element.className){ element.className=value; }else{ newClassName=element.className; newClassName+=" "; newClassName+=value; element.className=newClassName; ... 阅读全文
posted @ 2012-02-14 16:09 猪弟 阅读(251) 评论(0) 推荐(0)