看到消息说chrome支持template标签,试了一下,要安装最新的版本chrome canary才能看到效果。
<template id="hhhhold-template">
<img src="http://www.haha365.com/uploadfile/2011/1210/20111210102032473.gif" alt="random hhhhold image">
<h3 class="title"></h3>
<script>alert(123)</script>
</template>
<script>
window.onload = function(){
var template = document.querySelector('#hhhhold-template');
//template.content.querySelector('img').src = 'http://www.haha365.com/uploadfile/2011/1210/20111210102032473.gif';
template.content.querySelector('.title').textContent = 'Random image from hhhhold.com'
document.body.appendChild(template.content.cloneNode(true));
};
</script>