<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> web component </title>
<link rel="import" href="./webComponent/netease-color.html">
</head>
<body>
<h1>angular</h1>
<netease-color></netease-color>
</body>
</html>
<template>
<style>
.color {
color: red;
}
</style>
<p>My favorite color is : <strong class="color">Red</strong></p>
</template>
<script>
(function() {
var element = Object.create(HTMLElement.prototype);
var template = document.currentScript.ownerDocument.querySelector('template').content;
element.createdCallback = function(){
var shadowRoot = this.createShadowRoot();
var clone = document.importNode(template, true);
shadowRoot.appendChild(clone);
};
document.registerElement('netease-color', {
prototype: element
});
})
</script>
网友评论