jquery的两种表示:在jquery中jQuery是关键字,和$的作用相同,下面代码作用相同

#通过id值获得jquery对象
$("#demo")
jQuery("#demo")

jquery对象和dom对象的转换

//代码示例
<div class="demo">
  <ul class="lang">
    <li class="js dy">JavaScript</li>
    <li class="dy">Python</li>
    <li id="swift">Swift</li>
    <li class="dy">Scheme</li>
    <li name="haskell">Haskell</li>
  </ul>
</div

$('li'); 
//获得的是jquery对象,类似于数组,表现形式为[li.js.dy, li.dy, li#swift, li.dy, li]
//如果想获得jquery对象的html表示,则可以通过$('li').prop("innerHTML"),或者通过$('li').get(0)

#jquery对象和dom对象的转换
instance = $('.demo').get(0); //get(0)返回的是一个dom对象,<div class="demo">..</div>
$(".demo").get();// get()返回的是jquery对象,为[div.demo]
$(instance) ;//将dom对象转化为jquery对象

记忆:

选择器:id选择器,class选择器,tag选择器,属性选择器,组合选择器,多项选择器,层级选择器,父子选择器

查找:parents、parent;closest;first、last、slice;prev、next;find;children; filter、map、each

操作:text,html; css,hasClass,addClass,removeClass; hide,show,toggle; attr,removeAttr, prop; val; append,prepend,after,before; remove,empty;

results matching ""

    No results matching ""