JS对象和jQuery对象的相互转换

jQuery–>js
有两种转换方法

   var jq=$('#btn');
    var js=jq[0];//第一种
  //var js=jq.get[0];//第二种
   js.onclick=function(){
       console.log(1);
   };

js---->jQuery
$():jQuery对象的加工厂

   var jsDiv=document.getElementById('div');
  var js=document.getElementById('btn');
    js.onclick=function(){
        var jqDiv=$(jsDiv);//$是jQuery的替代符
        jqDiv.hide();//隐藏
    }

猜你喜欢

转载自blog.csdn.net/weixin_43893437/article/details/84782518
今日推荐