jQuery引入细节

题目:按照课程内容,补全下面的代码,并记录实现过程

window.jQuery = ???
window.$ = jQuery
var $div = $('div')
$div.addClass('red') // 可将所有 div 的 class 添加一个 red
$div.setText('hi') // 可将所有 div 的 textContent 变为 hi

完整代码:

HTML



  
  JS Bin


CSS
.div.red{
  background:red;
}
.div{
  width:30px;
  height:30px;
  border:2px solid black;
  background:blue;
  border-radius:50%;
  text-align:center;
}

JS
window.jQuery=function(nodeOrSelector){
  let nodes={}
  if(typeof nodeOrSelector==='string'){
    let temp=document.querySelectorAll(nodeOrSelector)
    for(let i=0;i {
    for (let i = 0; i < nodes.length; i++) {
        nodes[i].classList.add(value)
      }
     })
   } else if (typeof classes === 'string') {
    for (let i = 0; i < nodes.length; i++) {
     nodes[i].classList.add(classes)
    }
   }
}
  nodes.setText=function(text){
     for(let i=0;i

细节记录:

https://www.jianshu.com/p/804ac714e288

你可能感兴趣的:(jQuery引入细节)