jquery 獲取及操做元素 (經常使用)

jquery 獲取元素  參考:http://www.w3school.com.cn/jquery/jquery_selectors.aspcss

1.(1)$(document).ready() -->$()-->$  整個文檔html

   (2)$("p") $("button") html標籤jquery

   (3)$(this) 當前對象sql

1 $(function(){
2   $("p").click(function(){
3     $(this).hide();
4   });
5 });

  (4)根據id獲取對象 $("#divs")ide

  (5)根據class獲取對象 $(".clsdiv")this

  (6)根據name獲取對象 $("[name='sql']")spa

2.操做code

  (1)$("[name='sql']").css({"color" : "gray"});htm

  (2)對象

 1 $(document).ready(function(){
 2   $("#btn1").click(function(){
 3     $("#test1").text("Hello world!");
 4   });
 5   $("#btn2").click(function(){
 6     $("#test2").html("<b>Hello world!</b>");
 7   });
 8   $("#btn3").click(function(){
 9     $("#test3").val("Dolly Duck");
10   });
11 });

  (3)attr  

1 $("button").click(function(){
2   $("img").attr("width","180");
3 });
1 $(selector).attr({attribute:value, attribute:value ...})
2 $(selector).attr(attribute,function(index,oldvalue))
3 $(selector).attr(attribute,value)
$(selector).attr(attribute)

 

 

$(".clsdiv")

相關文章
相關標籤/搜索