随笔分类 - JavaScript常用函数收录
收录JS常用函数
摘要:function selectFrom(iFirstValue,iLastValue){ var iChoices=iLastValue-iFirstValue+1; return Math.floor(Math.random()*iChoices+iFirstValue); }
阅读全文
摘要: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...
阅读全文
摘要:function insertAfter(newElement,targetElement){ var parent=targetElement.parentNode; if(parent.lastChild==targetElement){ parent.appendChild(newElement); }else{ parent.insertBefore(newElement,targetElement.nextSibling) } }相对于insertBefore()编写的i...
阅读全文
摘要:function addLoadEvent(func){ var oldonload=window.onload; if(typeof window.onload!='function'){ window.onload=func; }else{ window.onload=function(){ oldonload(); func(); } } }注意调用的时候:addLoadEvent(func);...
阅读全文
摘要:function addClass(element,value){ if(!element.className){ element.className=value; }else{ newClassName=element.className; newClassName+=" "; newClassName+=value; element.className=newClassName; ...
阅读全文

浙公网安备 33010602011771号