image.png
html
<body>
<input type="text" foucs name="hd">
<ul>
</ul>
</body>
js
<script type="text/javascript">
let obj={
data:new Set(), //把new set赋值给data
set keyword(word){
this.data.add(word)
},
show(){
let uL=document.querySelector('ul') //获取 ul
console.log('1',this.data) //等于 new set([1,2,3])
uL.innerHTML=''
this.data.forEach(function(val){//循环 new set([1,2,3])
console.log(';for',val)//1,2,3
uL.innerHTML=`<li>${val}<li/>`;
})
console.log(this.data)
}
}
let input=document.querySelector("[name='hd']") //获取 <input type="text" foucs name="hd">
input.addEventListener('blur',function(){
console.log(this.value)//获取input的值
// obj.keyword(this.value)
obj.keyword=this.value;
obj.show()
})
</script >
网友评论