Jquery 學習

1. 選擇器

  $(this)   適用於對於某一具體對象的操作

                   eg: $(“form”).submit(function(){

                             $(this) .XXXXX
                        });

$(A > B) 得到A下直接子標籤爲B的集合   可以使用[]訪問子元素
$("#id")  以#開始 查找相關id的對象

$(".class")  以.開始 查找相關class 的對象

$("p")  html標籤  查找符合html標籤的對象

$("a,b,c")  只要符合一種則返回 a b c 爲有效的選擇器,可以任意多個 ,分割

$("a b")   滿足a下 b的選擇器,a b 可以是任意的有效,不用直接子 可以一直弄下去 空間 空格 分割等級

$("A + B")  滿足緊跟A的B  都是有效的選擇器   
$("A ~ B") 同一等級的 標籤 與A同一等級的B標籤
$('A:first')  滿足A條件的第一個元素

$('A:last')  滿足A條件的最後一個元素

$("A:not(B)") 滿足A條件下不滿足B的集合  A B 都是選擇器 
$("A:even")  滿足所有A條件下的偶數
$("A:odd") 滿足所有A條件下的奇數
$("A:eq(index)") A下第index 的對象
$("A:gt(index)") A下索引值大於index
$("A:lt(2)") A下索引值小於index
$( document.activeElement ) 得到當前焦點所對應的元素

$(":root") 跟元素 html

$("A:parent")  經過A選擇器後,選擇含有文本或者含有子元素的對象
$("A:hidden")  經過A選擇器後,type爲hidden 或者隱藏的對象

$("A:visible")
經過A選擇器後,可見的對象

$("A[attribute]") 含有某種屬性的滿足A選擇器的對象
$("A[attribute='value'] (此= 可以變爲 !=  ^=  $=  *=)
含有某種屬性的滿足A選擇器的對象 ,且屬性值一定的對象
$([selector1][selector2][selectorN]) 使用中括號括起來
$("A:contains('string')") 滿足A條件下,同時含有string的標籤
$("A:empty") 不包含元素的A選擇器 選擇的結果

:first-child 

:first-of-type

:last-child

:last-of-type

:checked

:selected

:disabled

:enabled

 下面這幾個不能直接連在選擇器 後面 ,即不能

$("div:input")  X錯誤

$(":input")
$(":text")
$(":password") 
$(":radio")
$(":checkbox")
$(":submit")
$(":reset")
$(":button")
$(":file")

2.選擇器後,可以使用的篩選方法(有些與上面的混合選擇器類似的功能)

.eq(index)

.first() 

.last()

.hasClass('c')

.is(' ') 其中可以是選擇器,也可以是dom元素

.filter(' ') 如上

.has()

.not()

.children(' ') 可以加入選擇器 或者不加

.find(' ')

.next()

.nextAll()

.parent()


4.對象的css修改

$("A").css("key", "value");

5.對象中的內容修改

   $("tr,div").text()  .text('    ')

  $("tr,div").val()       .val('   ')

$("tr,div").innerHTML() 沒有此方法,

$("tr,div").addClass('');

.removeClass('    ')

.attr('attribute')

.attr('attribute','value')

.removeattr('attribute')

.html()

.html('   ')

6.文檔的處理

  append()

appendTo()

after()

before()

insertAfter()

replaceAll()

replaceWith()

remove()

clone()

7.常用的事件

 ready

 click

submit

focus

blur

mousedowm(over out move leave  enter)

hover

keypress (down up)

resize

scroll

select

unload

change

dbclick

8.還有一些效果 如同html 的效果

show  hide  toggle slideDown slideUp fadeIn fadeOut

9. 遍歷對象的方法

$.each(對象集合,function(){})

例如:

$.each($("tr"),function(){
         alert($(this).text());
        
        });





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章