js常用方法(。。。。不完整)
lastIndexOf();
substring();
split();
slice();
splice();
var s="http://www.baidu.com"; var i= s.lastIndexOf("."); //16 var unit= s.substring(i); //.com var url= s.substring(0,i); //http://www.baidu
addLoadEvent(func1); addLoadEvent(func2); function addLoadEvent(func){ var oldonload=window.onload; if(typeof window.onload!='function'){ window.onload=func; }else{ window.onload=function() { oldonload(); func(); } } }; function func1(){ alert("text1"); }; function func2(){ alert("text2"); };
<ul id="imagegallery"> <li><a href="images/ads/1.jpg" title="广告1">广告1</a></li> <li><a href="images/ads/2.jpg" title="广告2">广告2</a></li> <li><a href="images/ads/3.jpg" title="广告3">广告3</a></li> <li><a href="images/ads/4.jpg" title="广告4">广告4</a></li> </ul> <p id="description">Choose an image</p> <img id="placeholder" src="images/ads/adindex.gif" alt="my image gallery">
window.onload = prepareGallery(); function prepareGallery() { if (!document.getElementsByTagName) return false; if (!document.getElementById) return false; if (!document.getElementById("imagegallery")) return false; var gallery = document.getElementById("imagegallery"); var links = gallery.getElementsByTagName("a"); for (var i = 0; i < links.length; i++) { links[i].onclick = function () { return showPic(this) ? false : true; } } } function showPic(whichpic) { if (!document.getElementById("placeholder")) return false; var sourse = whichpic.getAttribute("href"); var placeholder = document.getElementById("placeholder"); if (placeholder.nodeName != "IMG") return false; placeholder.setAttribute("src", sourse); // if (document.getElementById("description")) { var text = whichpic.getAttribute("title") ? whichpic.getAttribute("title") : ""; var description = document.getElementById("description"); if (description.firstChild.nodeType == 3) { description.firstChild.nodeValue = text; } } return true; }