HTML Import时引用不过来,一直报错null,谁知道为什么么
`
<head lang='en'>
<link ref='import' href='importSub.html'/>
</head>
<body>
<script>
window.onload = function(){
var s = document.querySelector('link[ref="import"]').import;
var t = s.querySelector('h1')
document.body.appendChild(t)
}
</script>
</body>
`
importMain.html:13 Uncaught TypeError: Cannot read property 'querySelector' of null
拼写错误,“rel”写成“ref”了。
js的部分不太熟,不知道有没有问题。但据我所知link标签的这种写法可能会有兼容性问题,得上个谷歌的polyfill,就是webcomponents.js
既然这样,也可以用jQ的
.load()
呀。