动态添加s 文件的方法
来源:互联网 发布:c高级编程 编辑:程序博客网 时间:2024/06/05 03:57
- script type="text/javascript" src="http://ext.weather.com.cn/8888.js"></script>
那么你的脚本应当为:
- <!DOCTYPE>
- <html>
- <head>
- <title></title>
- </head>
- <body>
- <div>
- <div id="gadgetContainer">
- </div>
- </div>
- <script type="text/javascript">
- window.loadGadget = function () {
- var codeUrl = 'http://ext.weather.com.cn/8888.js'
- var containerID = 'gadgetContainer'
- var s = document.createElement('script')
- s.type = 'text/javascript'
- s.src = codeUrl + '?target=' + containerID
- document.body.appendChild(s)
- }
- window.onload = window.onload ? function () {
- window.onload()
- window.loadGadget()
- } : window.loadGadget
- </script>
- </body>
- </html>
当然您也可以将脚本存到外部.js文件中,那么您的页面看起来就会是这样:
- <!DOCTYPE>
- <html>
- <head>
- <title></title>
- </head>
- <body>
- <div>
- <div id="gadgetContainer"></div>
- </div>
- <script type="text/javascript" src="lazyloadGadget.js"></script>
- </body>
- </html>
而lazyloadGagdet.js中的代码是:
- window.loadGadget = function () {
- var codeUrl = 'http://ext.weather.com.cn/8888.js'
- var containerID = 'gadgetContainer'
- var s = document.createElement('script')
- s.type = 'text/javascript'
- s.src = codeUrl + '?target=' + containerID
- document.body.appendChild(s)
- }
- window.onload = window.onload ? function () {
- window.onload()
- window.loadGadget()
- } : window.loadGadget
应当注意,请将延迟加载脚本放在紧贴body结束标签 </body>
之前!
- 动态添加s 文件的方法
- 在source Insight中添加s文件的方法
- Linux下添加动态库文件的方法
- Android Studio 添加动态库os文件的方法
- 动态添加SiteMapPath的方法
- SourceInsight添加对汇编语言文件.s和.S的支持
- 添加库文件的方法
- 动态的添加多个上传文件
- 动态添加文件的输入项
- 文件上传的动态添加输入项
- 文件上传的动态添加输入项
- js动态添加事件的方法
- js动态添加事件的方法!()
- js动态添加事件的方法
- js动态添加事件的方法
- VC 控件动态添加的方法
- JS动态添加事件的执行方法.
- 技巧 Html元素的动态添加方法
- 有用的mini itx主板(多pcie)
- VirtualBox安装Ubuntu时不能全屏
- Deep Learning论文笔记之(七)深度网络高层特征可视化
- ASP.NET MVC中在Action获取提交的表单数据方法总结 .
- 午后街头、写封信给未来。
- 动态添加s 文件的方法
- 好记心,不如烂笔头
- android-settings添加字体更换-前篇-setting简单一览
- android存储方式
- mvc项目中,解决用Url.Content方法引用jquery文件后智能提示失效的办法
- ios中自定义cell,自定义UITableViewCell
- s3c6410中断处理
- 交通灯管理系统和银行业务调度系统学习
- HTML5 LocalStorage本地存储和sessionStorage使用