JavaScript预加载和在插入元素封装
//封装加载 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);
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现