JQuery语法:查找+操作

jquery的基础语法:$(selector).action() 即查找元素.操作
一、查找元素(选择器和筛选器)
1.1 选择器
1.1.1 基本选择器
$("*") $("#id") $(".class") $(“element”) $(".class,p,div")
1.1.2 层级选择器
$(".outer div") $(".outer>div") $(".outer+div") $(".outer~div")
1.1.3 基本筛选器
$(“li:first”) $(“li:eq(2)”) $(“li:even”) $(“li:gt(1)”)
1.1.4 属性选择器
$(’[id=“div1”]’) $(’[“alex=“sb”][id]’)
1.1.5 表单选择器
( " [ t y p e = ′ t e x t ′ ] " ) − − − − − > ("[type='text']")-----> ("[type=text]")>(”:text") 注意只适用于input标签 : $(“input:checked”)
1.2 筛选器
1.2.1 过滤筛选器
$(“li”).eq(2) $(“li”).first() $(“ul li”).hasclass(“test”)
1.2.2 查找筛选器
$(“div”).children(".test") $(“div”).find(".test")

 $(".test").next()    $(".test").nextAll()    $(".test").nextUntil()
                           
 $("div").prev()  $("div").prevAll()  $("div").prevUntil()   
                        
 $(".test").parent()  $(".test").parents()  $(".test").parentUntil()
 
 $("div").siblings()

二、操作
1、属性操作
--------------------------属性
$("").attr();
$("").removeAttr();
$("").prop();
$("").removeProp();
--------------------------CSS类
$("").addClass(class|fn)
$("").removeClass([class|fn])
--------------------------HTML代码/文本/值
$("").html([val|fn])
$("").text([val|fn])
$("").val([val|fn|arr])
---------------------------
$("").css(“color”,“red”)

2、文档处理

创建一个标签对象
$("

")
内部插入
( " " ) . a p p e n d ( c o n t e n t ∣ f n ) − − − − − > ("").append(content|fn) -----> ("").append(contentfn)>(“p”).append(“Hello”);
( " " ) . a p p e n d T o ( c o n t e n t ) − − − − − > ("").appendTo(content) -----> ("").appendTo(content)>(“p”).appendTo(“div”);
( " " ) . p r e p e n d ( c o n t e n t ∣ f n ) − − − − − > ("").prepend(content|fn) -----> ("").prepend(contentfn)>(“p”).prepend(“Hello”);
( " " ) . p r e p e n d T o ( c o n t e n t ) − − − − − > ("").prependTo(content) -----> ("").prependTo(content)>(“p”).prependTo("#foo");
替换
( " " ) . r e p l a c e W i t h ( c o n t e n t ∣ f n ) − − − − − > ("").replaceWith(content|fn) -----> ("").replaceWith(contentfn)>(“p”).replaceWith("Paragraph. ");

删除
$("").empty()
$("").remove([expr])

复制
$("").clone([Even[,deepEven]])
3、css操作
CSS
$("").css(name|pro|[,val|fn])
位置
$("").offset([coordinates])
$("").position()
$("").scrollTop([val])
$("").scrollLeft([val])
尺寸
$("").height([val|fn])
$("").width([val|fn])
$("").innerHeight()
$("").innerWidth()
$("").outerHeight([soptions])
$("").outerWidth([options])


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值