jquery框架 ————2021-08-22

news/2024/7/19 13:35:59 标签: jquery, javascript, css, js, html

html" title=jquery>jquery框架——————8月22号

    • 选择器
    • 过滤器:

html" title=jquery>jquery = html" title=javascript>javascript + query; html" title=js>js代码编写;写的更少,做的更多;

onload:页面加载函数,整个页面加载到内存中自动调用*html" title=js>js代码;

html" title=javascript>javascript">//一加载就执行
			window.onload = function() {
				console.log(111);
			}

1、导入html" title=jquery>jquery的html" title=js>js;2、编写html" title=js>js代码; ($代替html" title=jquery>jquery)

html" title=javascript>javascript"><script src="html" title=js>js/html" title=jquery>jquery-1.8.3.min.html" title=js>js" type="text/html" title=javascript>javascript" charset="utf-8"></script>

html" title=jquery>jquery文档加载函数 $=html" title=jquery>jquery (同上,可替代,并且比onload先执行)

html" title=javascript>javascript">	$(function(){
				console.log(222);
			})

使用on绑定事件,使用off解绑事件;

html" title=javascript>javascript">    $("#btn").on("click",function(){
					alert("单击");
				})
				
				 $("#btn").mouseover(function(){
					console.log("鼠标悬浮");
				}) 
				
				$("#btn2").click(function(){
					//$("#btn").off("click"); //解绑指定事件
					$("#btn").off(); //解绑所有事件
				})
this代表当前对象;hide():隐藏方法;html():获取内容;
html" title=javascript>javascript">     $("p").mouseover(function(){
					$(this).hide(); //隐藏当前对象
				})
				
				$("p").click(function(){
					alert($(this).html()); //获取当前内容`在这里插入代码片
				})

遍历:for循环与jq对比;

html" title=javascript>javascript">	//遍历 for循环
				var li = document.getElementsByTagName("li");
				for(var i = 0;i < li.length;i++){
					console.log(li[i].innerHTML);
				}
				//html" title=jquery>jquery 循环 each方法
				$("ul>li").each(function(i,o){
					console.log(i); //拿到索引
					console.log(o.innerHTML); //拿到元素
					console.log($(o).html()); //jq对象 拿到元素
					//console.log($(this).html());
				})

jq添加html" title=css>css样式:

html" title=javascript>javascript">	<style type="text/html" title=css>css">
			.h{
				width: 300px;
				color:mediumvioletred;
				border: 2px solid;
			}
		    </style>
 
            <h1>Hello JQuery</h1>
 
 
            	$("h1").mouseover(function(){
					// $(this).addClass("h"); //添加class
					$(this).html" title=css>css("color","blue");
				}).mouseout(function(){
					// $(this).removeClass("h"); //移除class
					$(this).html" title=css>css("color","pink");
				})

html" title=jquery>jquery对象与dom对象之间的相互转换:

html" title=javascript>javascript"><input type="" name="" id="username" value="请输入用户名" />
 
		<script type="text/html" title=javascript>javascript">
			$(function() {
 
				var username = document.getElementById("username");
				console.log(username.value);
				//dom对象转为html" title=jquery>jquery对象:使用$(dom对象),$()称为工厂函数
				console.log($(username).val());
				//html" title=jquery>jquery对象转换为dom对象:1、类似数组元素访问方式
				var $username = $(username);
				var username2 = $username[0];
				console.log(username2.value);
				//2、get(0)方法
				var username3 = $username.get(0);
				console.log(username3.value);
			})
		</script>

选择器

基本选择器加样式:

html" title=javascript>javascript">  $(".h1").html" title=css>css("background-color","#ccc");
  $(".h2,#p,.li").html" title=css>css({"color":"orange","border":"1px solid"});
 $("*").html" title=css>css({"background-color":"pink","border":"1px solid #000"});

层级选择器:
ancestor descendant:空格,获取ancestor下所有的descendant元素;(“form input”);
parent>child:父子选择器;获取子元素;$(“form>input”);
prev + next:相邻兄弟选择器;获取紧随prev元素后的一个兄弟元素;(“label+input”);
prev ~ siblings:通用兄弟选择器;获取prev元素后边的所有兄弟元素;(“form~input”);

过滤器:

基本过滤选择器:
:first 选取第一个元素;$(“tr:first”);
:last 选取最后一个元素;
:not(selector) 去除所有与给定选择器匹配的元素;
:even 选取所有元素中偶数索引的元素,从0开始计数;
:odd 选取所有元素中奇数索引的元素;
:eq(index) 选取指定索引的元素;
:gt(index) 选取索引大于指定index的元素;
:lt(index) 选取索引小于指定index的元素;
:header 选取所有的标题元素;
:animated 匹配所有正在执行动画效果的元素;

内容过滤选择器:
:contains(text) 选取包含text文本内容的元素;$(“div:contains(‘John’)”);
:empty 选取不包含子元素或者文本节点的空元素;
:has(selector) 选取含有选择器所匹配的元素的元素;(“div:has ( p )”);
:parent 选取含有子元素或文本节点(内容)的元素;

可见性过滤选择器:
:hidden 选取所有不可见的元素$(“tr:hidden”) 匹配所有display:none、input中type=hidden的元素;
:visible 选取所有可见的元素;

html" title=javascript>javascript">    $("input:eq(1)").click(function(){
					$(":hidden").show(); //show方法显示
				})
				
				$("input:last").click(function(){
					$("#di:visible").hide();
				})

属性过滤选择器:
[attribute] 选取拥有此属性的元素;$(“div[id]”);
[attribute = value] 选取指定属性值为value的所有元素;
[attribute != value] 选取属性值不为value的所有元素;
[attribute ^= value] 选取属性值以value开始的所有元素;
[attribute $= value] 选取属性值以value结束的所有元素;
[attribute *= value] 选取属性值包含value的所有元素;
[selector1] [selector2] ……[selectorN] 复合性选择器;

子元素过滤选择器:
对某元素中的子元素进行选取
:nth-child(index/even/odd) 选取索引为index的元素、索引为偶数、索引为奇数的元素—index从1开始;
:first-child 此选择符将为每个父元素匹配第一个子元素;
:last-child 次选择符将为每个父元素匹配最后一个子元素;
:only-child 选取唯一子元素,它的父元素只有它这一个子元素;

表单过滤选择器:根据元素类型进行选择

选取表单元素的过滤选择器
:input 选取所有、 、 和元素;
:text 选取所有的文本框元素;
:password 选取所有的密码框元素;
:radio 选取所有的单选框元素;
:checkbox 选取所有的多选框元素;
:submit 选取所有的提交按钮元素;
:image 选取所有的图像按钮元素;
:reset 选取所有重置按钮元素;
:button 选取所有按钮元素;
:file 选取所有文件上传域元素;
:hidden 选取所有不可见的元素;
注:$(“input[type=‘checkbox’]”)----等于:checkbox

blur(function) 离焦事件;
val() 可以获取表单元素value属性,表单中的值;
attr() 可以获取对象的属性值;

表单对象属性过滤选择器:根据元素特殊属性进行选择;
:enabled 选取所有可用元素;
:disabled 选取所有不可用元素;
:checked 选取所有被选中的元素,如单选框、复选框;
:selected 选取所有被选中项元素,如下拉列表框、列表框;


http://www.niftyadmin.cn/n/838222.html

相关文章

java修饰符使用指南

java修饰符使用指南 1、什么是修饰符&#xff1f; 指的是一种标识类型以及类型成员的访问范围的声明。应用在修饰类名&#xff0c;类成员&#xff0c;方法&#xff0c;参数&#xff0c;构造器中。2、修饰符的有几种? 一共大致有14种&#xff0c;分别为public、private、protec…

SpringMVC (八)SpringMVC返回值类型

SpringMVC的返回值类型有MedelAndView&#xff0c;String&#xff0c;void,Object数值型&#xff0c;集合类型等等 前两种我们之前写案例的时候一直在用&#xff0c;现在看一下返回值是void 第一种&#xff1a;返回viod 返回值是void的话&#xff0c;就要结合ajax来写 准备一个…

基于Docker的阿里云RDS从库部署

1.获取备份文件&#xff0c;从阿里控制台上可以下载 2.解压 获取解压脚本 wget http://oss.aliyuncs.com/aliyunecs/rds_backup_extract.sh?spm5176.775973700.0.0.n9b8wj&filerds_backup_extract.sh -O rds_backup_extract.sh 执行解压 bash rds_backup_extract.sh -f fu…

JSP 2021-08-23

jspapache tomcat需要导入的jar包一、jsp简介二、jsp的运行原理三、jap三种脚本元素 --jsp书写Java代码**小结&#xff1a;**1 session与Cookiesservlet与jsp四 、 jsp指令1 page指令 (一定要认识)A 字符集编码设置2 include指令—静态引入jspA include静态指令图示&#xff1a…

美的集团收购库卡集团要约期结束 已占库卡85.69%股权

美的集团要约收购库卡集团又有关键进展。公司今日公告&#xff0c;截至北京时间7月16日&#xff0c;要约收购库卡集团的要约期已经结束。在要约期内&#xff0c;接受本次要约收购的库卡集团股份数量合计为2871.00万股&#xff0c;占库卡集团已发行股本的比例为72.18%。目前&…

聚焦爬虫:定向抓取系统的实现方法

文章来源&#xff1a;http://www.biaodianfu.com/mplementation-of-targeted-crawling-system.html 网络爬虫是一个自动提取网页的程序&#xff0c;它为搜索引擎从万维网上下载网页&#xff0c;是搜索引擎的重要组成。传统爬虫从一个或若干初始网页的URL开始&#xff0c;获得初…

Shell之二

Shell第1章 条件表达式1.1 判断一个文件或者目录是否存在[rootnfs01 scripts]# [ -f /etc/hosts ] && echo "file true" || echo "file fleas"file true[rootnfs01 scripts]# [ -f /etc/hostaaas ] && echo "file true" || echo…

网络爬虫基本原理二

文章来源&#xff1a;http://www.cnblogs.com/wawlian/archive/2012/06/18/2554072.html 四、更新策略互联网是实时变化的&#xff0c;具有很强的动态性。网页更新策略主要是决定何时更新之前已经下载过的页面。常见的更新策略又以下三种&#xff1a;1.历史参考策略顾名思义&am…