//封装加载
function addLoadEvent(func) {
var oldonload = window.onload;
if(typeof window.onload !== 'function'){
window.onload = func;
}
else {
window.onload = function() {
oldonload();
func();
}
}
}
//使用
function loadEvents() {
// home
prepareSlideshow();
// about
prepareInternalnav();
// photos
preparePlaceholder();
prepareGallery();
// live
stripeTables();
highlightRows();
displayAbbreviations();
// contact
focusLabels();
prepareForms();
}
// Load events
addLoadEvent(highlightPage);
addLoadEvent(loadEvents);
//封装插入元素
function insertAfter(newElement, targetElement) {
var parent = targetElement.parentNode;
if (parent.lastChild === targetElement) {
parent.appendChild(newElement);
}
else {
parent.insertBefore(newElement, targetElement.nextSibling);
}
}
//使用
var intro = document.getElementById('intro');
var slideshow = document.createElement('div');
slideshow.setAttribute('id','slideshow');
var frame = document.createElement('img');
frame.setAttribute('src','images/frame.gif');
frame.setAttribute('alt','');
frame.setAttribute('id','frame');
slideshow.appendChild(frame);
var preview = document.createElement('img');
preview.setAttribute('src','images/slideshow.gif');
preview.setAttribute('alt','a glimpse of what awaits you');
preview.setAttribute('id','preview');
slideshow.appendChild(preview);
//在这里
insertAfter(slideshow,intro);