jquery---4

来源:互联网 发布:mac怎样下载bilibili 编辑:程序博客网 时间:2024/04/27 22:36

+Changing CSS styles with the css() method 

+More animation as you meet jQuery’s animate() method

+Inserting, removing, and moving elements around the DOM

+Editing element attributes with attr()

+A myriad of manipulation methods that jQuery provides 

》 If you want to add a class to something, you can do it regardless of whether the element already not.has that class not.  there’s no need to check whether an element has a class before you remove  that class. 

. slideUp(), slideDown(), slideToggle()  

      . slideUp will animate an element to a height of 0, creating the effect that the element slides up the page, with its    height getting smaller and smaller until it disappears. 

     想要点击之后再有效果即 $("#box").on("click",function(){$(this).slideUp();});

Removing Elements from the DOM

    jquery里有很多删除元素的方法,.remove( )   .detach( )    empty()

    区别:.remove( )会把其他与被修改元素相关的也删除掉,比如这个元素在click里作为eventhandler,remove这个元素后,click就不可用了,而.detach( ) 修改位置后,只要没有把这个元素在DOM中删除掉,在其他位置依旧可以使用。

Creating New Elements

   var newDiv = $("<div></div>", {
  "text": "Hello",
  "class": "newDiv",
  "title": "Hello"
});

》DOM Insertion, Inside:向DOM里添加 append()  appendTo()   html()   prepend()   prependTo()   text()

    append() adds that onto the end of each element in the set。$("p").append(***)元素是添加在<p>内部的。

    prepend() will insert elements at the beginning, before all other elements. 

    appendTo( ),prependTo( )用法与append()相反,但添加位置相同。都是在内部添加。

     $("<strong>hello</strong>").appendTo("p")

》DOM Insertion, Outside:after()  before()   insertAfter()   insertBefore()

     after()  is used to insert content after the elements in your set。$("p")after("***")元素是添加在<p>外部的

      $("<span>Hey</span>").insertAfter("p");

0 0
原创粉丝点击