在 网站制作 中有很多部分的代码是相同的,如footer部分,可以把这段代码提取出来,在别的页面调用。
index.ht ML
<!-- 底部加载外部文件 --> <footer class="footer"> </footer> <script> $(& # 39;.footer').load('conment/foot.html',function(responseTxt, stat usTxt,x hr ){ console. LOG ('responseTxt,statusTxt,xhr') // console.log(responseTxt) // console.log(statusTxt) // console.log(xhr) }) </script>
foot.html
<html lang="en"> <head> <t IT le>Document</title> <link rel="stylesheet" href="css/foot.css"></link> </head> <body> .. . </body> </html>
重点:
$('.footer').load()调用时必须在 服务器 环境中打开 HTML 文件才能成功,不能直接双击打开
打开后浏览器的路径 应该 是https://127.0.0.1:8020/index.html,
而不是file:///G:/html/index.html这样的路径,否则在大部分的浏览器上都无法使用。
再此建议使用HBuilder这款编辑器,在运行时会创建服务器环境,并且在局域网中在别的手机或 电 脑上预览。
在网站 制作 中有很多部分的代码是相同的,如footer部分,可以把这段代码提取出来,在别的页面调用。
index.html
<!-- 底部加载外部文件 --> <footer class="footer"> </footer> <script> $('.footer').load('conment/foot.html',function(responseTxt,statusTxt,xhr){ console.log('responseTxt,statusTxt,xhr') // console.log(responseTxt) // console.log(statusTxt) // console.log(xhr) }) </script>
foot.html
<html lang="en"> <head> <title>Document</title> <link rel="stylesheet" href="css/foot.css"></link> </head> <body> ... </body> </html>
重点:
$('.footer').load()调用时必须在服务器环境中打开HTML文件才能成功,不能直接双击打开
打开后浏览器的路径应该是https://127.0.0.1:8020/index.html,
而不是file:///G:/html/index.html这样的路径,否则在大部分的浏览器上都无法使用。
再此建议使用HBuilder这款编辑器,在运行时会创建服务器环境,并且在局域网中在别的手机或电脑上预览。
觉得 可用,就经常来吧! 欢迎评论哦!&nbs p; html5教程 ,巧夺天工,精雕玉琢。小宝典献丑了!
总结
以上是 为你收集整理的 html5教程-HTML5公共页面如何提取作为公用代码? 全部内容,希望文章能够帮你解决 html5教程-HTML5公共页面如何提取作为公用代码? 所遇到的问题。
如果觉得 网站内容还不错, 推荐好友。
查看更多关于html5教程-HTML5公共页面如何提取作为公用代码?的详细内容...