五星好评
html部分
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script type="module">
import Star from "./js/Star.js";
document.addEventListener(Star.STAR_SELECTED_EVENT,starSelectedHandler);
let star=new Star("服务评价");
star.position=2;
star.bool=true;
star.appendTo(document.body);
let star1=new Star("售后评价")
star1.appendTo(document.body);
function starSelectedHandler(e){
console.log(e.position,e.content);
}
</script>
</body>
</html>
js Star.js部分
import Utils from "./Utils.js";
export default class Star{
static STAR_SELECTED_EVENT="star_selected_Event";
constructor(content,bool){
// this就是new出的对象
this.arr=[];
this.position=-1;
this.bool=bool;
this.elem=this.createElem(content);
}
createElem(content){
if(this.elem) return this.elem;
let div=Utils.ce("div",{
height:"35px",
position:"relative"
});
let label=Utils.ce("label",{
fontSize:"16px",
marginRight: "10px",
display:"inline-block",
marginTop: "18px",
},{
textContent:content
});
div.appendChild(label);
for(let i=0;i<5;i++){
let span=Utils.ce("span",{
display: 'inline-block',
width:"16px",
height:"16px",
marginTop: "18px",
backgroundImage:"url(./img/commstar.png)"
}