<html>
<head>
<title>手写jquery插件</title>
<meta charset="utf-8">
<style>
</style>
</head>
<body>
手写jquery 插件 考虑扩展性
<p>第一</p>
<p>第二</p>
<p>第三</p>
</body>
</html>
<!-- <script src="../js/jquery.min.js"></script> -->
<script>
class jQuery{
constructor(selector){
const result=document.querySelectorAll(selector);
const length=result.length;
for(let i=0;i<length;i++){
this[i]=result[i]
}
this.length=length;
this.selector=selector
}
get(index){
return this[index]
}
each(fn){
for(let i=0;i<this.length;i++){
const elem=this[i]
fn(elem)
}
}
js 手写jquery插件
最新推荐文章于 2023-02-08 17:49:41 发布