在网站制作中有很多部分的代码是相同的,如footer部分,可以把这段代码提取出来,在别的页面调用。
<!-- 底部加载外部文件 --> <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文件才能成功,不能直接双击打开
打开后浏览器的路径应该是http://127.0.0.1:8020/,
而不是file:///g:/html/这样的路径,否则在大部分的浏览器上都无法使用。
在此建议使用hbuilder这款编辑器,在运行时会创建服务器环境,并且在局域网中在别的手机或电脑上预览。
到此这篇关于html5公共页面提取作为公用代码的方法的文章就介绍到这了,更多相关html5公共页面提取为公用代码内容请搜索移动技术网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持移动技术网!
您可能感兴趣的文章:
如您对本文有疑问或者有任何想说的,请 点击进行留言回复,万千网友为您解惑!
网友评论