jquery object access
1. each (callback): execute a function with each matching element as the context, return false; stop the loop; return true; jump to the next loop.
Let’s give an example:
$("img").each(function(){
$(this).toggle("example");
})
2. size() and length The same, both return the number of elements in the jquery object.
$("img").size(); or $("img").length;
3. get(): Get the set of all matching DOM elements (note that the return is a dom object, not a jquery object)
$("img").get().reverse();
4. get(index): get one of them matching elements. Index indicates which element is matched. Using the get(index) method allows you to operate an actual DOM element.
$("img").get(0);//Get the first matching img element
$(this).get(0) is equivalent to $(this)[0]
5. index(subject): Search for elements that match the object represented by the parameter, and return the index value of the corresponding element.
Selector-Basic
selector1, selector2, selectorN will merge the matched elements and return them together
$("div,span,p.myClass");
There are several similar syntax differences to note here:
1.$("span",this)
For example:
$("div.foo" ).click(function() {
$("span", this).addClass("bar");
});
2. $("div#hi "), $("p.intro")
For example:
$("div#hi" ).css("color","red");
3. $("form input")
For example:
$("form input") .css("border", "5px solid red");
要区别上面几种相似形式的不同意思。
选择器-层级
1.ancestor descendant在给定的祖先元素下匹配所有的后代元素
$("div input");//div下所有input
2.parent > child 在给定的父元素下匹配所有的子元素
$("div > input);//父元素下的子元素
3.prev + next 匹配所有紧接在prev元素后的next元素
$("div + span")//紧接在div后的span
4.prev ~ siblings 匹配prev元素之后的所有siblings元素
$("form ~ input")//找到所有与表单同辈的input元素
选择器-简单
1.:first 匹配找到的第一个元素
$("tr:first")//查找表格中第一行
2.:last 匹配找到的最后一个元素
$("tr:last")//匹配找到的最后一个元素
3.:not(selector) 去除所有与给定选择器匹配的元素
ps:jquery 1.3中,已支持复杂选择器了(例如::not(div a)和:not(div,a))
$("input not(:checked)")//所有未被选中的input元素
4.:even 匹配所有索引值为偶数的元素,从0开始计数
$("tr:even")//查找表格中偶数行
5.:odd匹配所有索引值为奇数的元素,从0开始计数
$("tr:odd")//查找表格中奇数行
6.:eq(index)匹配一个给定索引值的元素
$("tr:eq(1)")//查找第二行
7.:gt(index)匹配所有大于给定索引值的元素
$("tr:gt(0)")//查找大于0的所有行
8.:lt(index)匹配所有小于给定索引值的元素
$("tr:lt(2)")//查找小于2的所有行
9.:header 匹配如h1,h2,h3之类的标题元素
$(":header").css("background",red");//所有标题加上背景色
10.:animated 匹配所有正在执行动画效果的元素
选择器-内容:
1.:contains(text) 匹配包含给定文本的元素
$("div:contains('aaa')")查找所有包含有aaa的div元素
2.:empty()匹配所有不包含子元素或文本的空元素
$("td:empty")
3.:has(selector)匹配含有选择器所匹配的元素的元素
$("div:has(p)").addClass("test");//给所有包含p元素的div元素添加一个text类
4.:parent匹配含有子元素或者文本的元素
$("td:parent");//查找所有含有子元素或者文本的td元素
选择器-可见性:
1.:hidden匹配所有不可见元素,input元素的type属性为hidden的话也会被匹配
$("tr:hidden");//查找所有不可见的tr元素
2.:visible匹配所有可见元素
$("tr:visible");//查找所有可见的tr元素
选择器-属性:
1.[attribute]匹配包含给定属性的元素
$("div[id]")//查找所有含有id属性的div元素
2.[attribute=value]匹配给定的属性是某个特定值的元素
$("input[name='username']")//查所所有name=username的input元素
3. [attribute!=value]匹配所有不含有指定属性,或者属性不等于特定值的元素
此选择器等价于:not([attr=value]),要匹配含有特定属性但不等于特定值的元素,请使用[attr]:not([attr=value])
$("input[name!='username']")//查找所有name!=username的input元素
4. [attribute^=value]匹配给定的属性是以某些值开始的元素
$("input[name^='user'])//查找所有name以'newws'开始的input元素
5. [attribute$=value]匹配给定属性是以某些值结尾的元素
$("input[name$='letter']) //查找所有name以'letter'结尾的input元素
6. [attribute*=value]匹配给定的属性是以包含某些值的元素
$("input[name*='man']")//查找所有name包含'man'的input元素
7. [selector1][selector2][selectorN]复合属性选择器,冉要同时满足多个条件时用。
$("input[id][name='man']")//含有id属性,并且name为man的
选择器-子元素:
1.:nth-child(index/even/odd/equation)匹配其父元素下的第N个子或奇偶元素
$("ul li:nth-child(2)")//在每个ul查找第2个li
2. :first-child匹配第一个子元素
$("ul li:first-child")//在每个ul中查找第一个li
3.:las-child匹配最后一个子元素
$("ul li:last-child")// 在第个ul中查找最后一个li
4.only-child如果某个元素是父元素中唯一的子元素,那将会被匹配,如果父元素中含有其他元素,不会被匹配
$("ul li:only-child")//在ul中查找是唯一子元素的li
Selector-Form:
1.:input, :text, :password, :radio, :checkbox, :submit, :image, :reset, :button, :file
2. :hidden matches all invisible elements, or elements of type hidden
Selector - form object attribute:
1.:enable matches all available elements
$("input:enabled")//Find all available input elements
2.:disabled matches all unavailable elements
$("input:disabled")//matches all unavailable elements
3.:checked matches all selected selected elements (check boxes, radio boxes, excluding options in select)
$("input:checked")//Find all selected elements Checkbox element
4.:selected matches all selected option elements
$("select option:selected")//Find all selected option elements

实现方法:1、用“$("img").delay(毫秒数).fadeOut()”语句,delay()设置延迟秒数;2、用“setTimeout(function(){ $("img").hide(); },毫秒值);”语句,通过定时器来延迟。

修改方法:1、用css()设置新样式,语法“$(元素).css("min-height","新值")”;2、用attr(),通过设置style属性来添加新样式,语法“$(元素).attr("style","min-height:新值")”。

区别:1、axios是一个异步请求框架,用于封装底层的XMLHttpRequest,而jquery是一个JavaScript库,只是顺便封装了dom操作;2、axios是基于承诺对象的,可以用承诺对象中的方法,而jquery不基于承诺对象。

增加元素的方法:1、用append(),语法“$("body").append(新元素)”,可向body内部的末尾处增加元素;2、用prepend(),语法“$("body").prepend(新元素)”,可向body内部的开始处增加元素。

在jquery中,apply()方法用于改变this指向,使用另一个对象替换当前对象,是应用某一对象的一个方法,语法为“apply(thisobj,[argarray])”;参数argarray表示的是以数组的形式进行传递。

删除方法:1、用empty(),语法“$("div").empty();”,可删除所有子节点和内容;2、用children()和remove(),语法“$("div").children().remove();”,只删除子元素,不删除内容。

去掉方法:1、用“$(selector).removeAttr("readonly")”语句删除readonly属性;2、用“$(selector).attr("readonly",false)”将readonly属性的值设置为false。

on()方法有4个参数:1、第一个参数不可省略,规定要从被选元素添加的一个或多个事件或命名空间;2、第二个参数可省略,规定元素的事件处理程序;3、第三个参数可省略,规定传递到函数的额外数据;4、第四个参数可省略,规定当事件发生时运行的函数。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

SublimeText3 Mac version
God-level code editing software (SublimeText3)

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver CS6
Visual web development tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
