jsp完成用户登录

 

[java] view
plain copy

第陆章 jQuery中的事件,第五章jQuery事件

  1.加载DOM

  jQuery中,在$(document).ready()方法内注册的轩然大波,只要DOM就绪就会被执行,此时大概成分的关系文件未下载完。

  jQuery中的
load()方法,会在要素的onload事件中绑定2个处理函数。比如$(window).load(function(){…}),等价于JavaScript中的window.onload=function(){…},该办法需求等网页全部因素都加载完(包蕴管理文件)。

  二.事件绑定

  在文书档案装载完事后,能够为元素绑定事件来完毕都部队分操作。能够运用bind()方法来对匹配成分进行一定的风浪绑定。

  语法: bind(type,[data],fn);

图片 1<!DOCTYPE
html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“; <html
xmlns=”; <head> <meta
http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>4-2-3</title> <script
src=”../../scripts/jquery-1.3.1.js”
type=”text/javascript”></script> <link rel=”stylesheet”
type=”text/css” href=”../../css/style.css” /> <script
type=”text/javascript”> $(function(){ $(“#panel
h五.head”).bind(“click”,function(){ var $content = $(this).next();
if($content.is(“:visible”)){ $content.hide(); }else{ $content.show(); }
}) }) </script> </head> <body> <div id=”panel”>
<h5 class=”head”>什么是jQuery?</h5> <div
class=”content”>
jQuery是继Prototype之后又一个了不起的JavaScript库,它是三个由 John Resig
创立于2006年3月的开源项目。jQuery凭借简洁的语法和跨平台的包容性,不小地简化了JavaScript开发职员遍历HTML文书档案、操作DOM、处监护人件、执行动画和支付Ajax。它特殊而又优雅的代码风格改变了JavaScript程序员的安插性思路和编写程序的办法。
</div> </div> </body> </html> View Code
图片 2<!DOCTYPE
html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“; <html
xmlns=”; <head> <meta
http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>4-2-4</title> <script
src=”../../scripts/jquery-1.3.1.js”
type=”text/javascript”></script> <link rel=”stylesheet”
type=”text/css” href=”../../css/style.css” /> <script
type=”text/javascript”> $(function(){ $(“#panel
h5.head”).bind(“mouseover”,function(){ $(this).next().show(); });
$(“#panel h5.head”).bind(“mouseout”,function(){ $(this).next().hide();
}) }) </script> </head> <body> <div id=”panel”>
<h5 class=”head”>什么是jQuery?</h5> <div
class=”content”>
jQuery是继Prototype之后又三个美好的JavaScript库,它是一个由 John Resig
创造于200陆年一月的开源项目。jQuery凭借简洁的语法和跨平台的包容性,不小地简化了JavaScript开发职员遍历HTML文档、操作DOM、处管事人件、执行动画和付出Ajax。它越发而又优雅的代码风格改变了JavaScript程序员的布署思路和编写程序的办法。
</div> </div> </body> </html> View Code

  叁.合成事件

  jQuery中有三个合成事件,hover()方法与toggle()方法。

  hover() 语法:hover(enter,leave);  用来效仿光标悬停事件。

图片 3<!DOCTYPE
html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“; <html
xmlns=”; <head> <meta
http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>4-3-1</title> <script
src=”../../scripts/jquery-1.3.1.js”
type=”text/javascript”></script> <link rel=”stylesheet”
type=”text/css” href=”../../css/style.css” /> <script
type=”text/javascript”> $(function(){ $(“#panel
h5.head”).hover(function(){ $(this).next().show(); },function(){
$(this).next().hide(); }) }) </script> </head> <body>
<div id=”panel”> <h5 class=”head”>什么是jQuery?</h5>
<div class=”content”>
jQuery是继Prototype之后又三个美艳的JavaScript库,它是贰个由 John Resig
创制于200六年十一月的开源项目。jQuery凭借简洁的语法和跨平台的包容性,十分的大地简化了JavaScript开发人士遍历HTML文书档案、操作DOM、处总管件、执行动画和开发Ajax。它独特而又优雅的代码风格改变了JavaScript程序员的统一筹划思路和编写程序的格局。
</div> </div> </body> </html> View Code

  toggle()语法:toggle(fn一,fn二,…fnN); 用来效仿鼠标延续单击事件。

图片 4<!DOCTYPE
html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“; <html
xmlns=”; <head> <meta
http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>4-3-3</title> <script
src=”../../scripts/jquery-1.3.1.js”
type=”text/javascript”></script> <link rel=”stylesheet”
type=”text/css” href=”../../css/style.css” /> <script
type=”text/javascript”> $(function(){ $(“#panel
h5.head”).toggle(function(){ $(this).next().toggle(); },function(){
$(this).next().toggle(); }) }) /*$(function(){ $(“#panel
h5.head”).click(function(){ $(this).next().toggle(); }) })*/
</script> </head> <body> <div id=”panel”> <h5class=”head”>什么是jQuery?</h五> <div class=”content”>
jQuery是继Prototype之后又三个非凡的JavaScript库,它是2个由 约翰 Resig
创造于200六年四月的开源项目。jQuery凭借简洁的语法和跨平台的包容性,相当的大地简化了JavaScript开发职员遍历HTML文书档案、操作DOM、处管事人件、执行动画和支付Ajax。它尤其而又优雅的代码风格改变了JavaScript程序员的宏图思路和编写程序的方法。
</div> </div> </body> </html> View Code

  四.轩然大波冒泡

  意思就是说,页面上有三个成分响应同三个轩然大波。事件会安分守己DOM的层次结构像水泡一样不断往上至顶。

图片 5<!DOCTYPE
html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“; <html
xmlns=”; <head> <meta
http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>4-4-1</title> <style type=”text/css”> * {
margin: 0; padding: 0; } body { font-size: 13px; line-height: 130%;
padding: 60px; } #content { width: 220px; border: 1px solid #0050D0;
background: #96E555; } span { width: 200px; margin: 10px; background:
#666666; cursor: pointer; color: white; display: block; } p { width:
200px; background: #88八; color: white; height: 1陆px; } </style>
<script src=”../../scripts/jquery-壹.三.壹.js”
type=”text/javascript”></script> <script
type=”text/javascript”> $(function () { // 为span成分绑定click事件
$(‘span’).bind(“click”, function () { var txt = $(‘#msg’).html() +
“<p>内层span元素被点击.<p/>”; $(‘#msg’).html(txt); }); //
为div元素绑定click事件 $(‘#content’).bind(“click”, function () { var
txt = $(‘#msg’).html() + “<p>外层div成分被点击.<p/>”;
$(‘#msg’).html(txt); }); // 为body成分绑定click事件
$(“body”).bind(“click”, function () { var txt = $(‘#msg’).html() +
“<p>body成分被点击.<p/>”; $(‘#msg’).html(txt); }); })
</script> </head> <body> <div id=”content”>
外层div元素 <span>内层span元素</span> 外层div元素
</div> <div id=”msg”> </div> </body>
</html> View Code

  停止冒泡

图片 6<!DOCTYPE
html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“; <html
xmlns=”; <head> <meta
http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>Panel</title> <style type=”text/css”> * {
margin: 0; padding: 0; } body { font-size: 13px; line-height: 130%;
padding: 60px; } #content { width: 220px; border: 1px solid #0050D0;
background: #96E555; } span { width: 200px; margin: 10px; background:
#666666; cursor: pointer; color: white; display: block; } p { width:
200px; background: #88八; color: white; height: 16px; } </style>
<script src=”../../scripts/jquery-①.三.壹.js”
type=”text/javascript”></script> <script
type=”text/javascript”> $(function () { // 为span成分绑定click事件
$(‘span’).bind(“click”, function (event) { var txt = $(‘#msg’).html() +
“<p>内层span成分被点击.<p/>”; $(‘#msg’).html(txt);
event.stopPropagation(); // 阻止事件冒泡 }); // 为div成分绑定click事件
$(‘#content’).bind(“click”, function (event) { var txt =
$(‘#msg’).html() + “<p>外层div元素被点击.<p/>”;
$(‘#msg’).html(txt); event.stopPropagation(); // 阻止事件冒泡 }); //
为body成分绑定click事件 $(“body”).bind(“click”, function () { var txt =
$(‘#msg’).html() + “<p>body成分被点击.<p/>”;
$(‘#msg’).html(txt); }); }) </script> </head> <body>
<div id=”content”> 外层div元素
<span>内层span元素</span> 外层div元素 </div> <div
id=”msg”> </div> </body> </html> View Code
图片 7<!DOCTYPE
html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“; <html
xmlns=”; <head> <meta
http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>4-4-4</title> <style type=”text/css”> * {
margin: 0; padding: 0; } body { font-size: 13px; line-height: 130%;
padding: 60px; } #content { width: 220px; border: 1px solid #0050D0;
background: #96E555; } span { width: 200px; margin: 10px; background:
#666666; cursor: pointer; color: white; display: block; } p { width:
200px; background: #88八; color: white; height: 1陆px; } </style>
<script src=”../../scripts/jquery-一.叁.一.js”
type=”text/javascript”></script> <script
type=”text/javascript”> $(function () { // 为span成分绑定click事件
$(‘span’).bind(“click”, function (event) { var txt = $(‘#msg’).html() +
“<p>内层span成分被点击.<p/>”; $(‘#msg’).html(txt); return
false; }); // 为div成分绑定click事件 $(‘#content’).bind(“click”,
function (event) { var txt = $(‘#msg’).html() +
“<p>外层div成分被点击.<p/>”; $(‘#msg’).html(txt); return
false; }); // 为body成分绑定click事件 $(“body”).bind(“click”, function
() { var txt = $(‘#msg’).html() + “<p>body成分被点击.<p/>”;
$(‘#msg’).html(txt); }); }) </script> </head> <body>
<div id=”content”> 外层div元素
<span>内层span元素</span> 外层div元素 </div> <div
id=”msg”> </div> </body> </html> View Code

  阻止暗中同意行为

图片 8<!DOCTYPE
html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“; <html
xmlns=”; <head> <meta
http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title></title> <script
src=”../../scripts/jquery-1.3.1.js”
type=”text/javascript”></script> <script
type=”text/javascript”> $(function () { $(“#sub”).bind(“click”,
function (event) { var username = $(“#username”).val(); //获取成分的值
if (username == “”) { //判断值是不是为空
$(“#msg”).html(“<p>文本框的值无法为空.</p>”); //提醒新闻event.preventDefault(); //阻止暗许行为 ( 表单提交 ) } }) })
</script> </head> <body> <form
action=”test.html”> 用户名:<input type=”text” id=”username” />
<br /> <input type=”submit” value=”提交” id=”sub” />
</form> <div id=”msg”> </div> </body>
</html> View Code
图片 9<!DOCTYPE
html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“; <html
xmlns=”; <head> <meta
http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title></title> <script
src=”../../scripts/jquery-1.3.1.js”
type=”text/javascript”></script> <script
type=”text/javascript”> $(function () { $(“#sub”).bind(“click”,
function (event) { var username = $(“#username”).val(); //获取成分的值
if (username == “”) { //判断值是或不是为空
$(“#msg”).html(“<p>文本框的值不能够为空.</p>”); //提醒信息return false; } }) }) </script> </head> <body>
<form action=”test.html”> 用户名:<input type=”text”
id=”username” /> <br /> <input type=”submit” value=”提交”
id=”sub” /> </form> <div id=”msg”> </div>
</body> </html> View
Code

  伍.风浪指标的属性

  jQuery对事件指标常用的习性实行了打包。

  (壹)event.type 能够博得事件的档次

图片 10<!DOCTYPE
html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“; <html
xmlns=”; <head>
<title></title> <meta http-equiv=”Content-Type”
content=”text/html; charset=utf-8″ /> <!– 引入jQuery –>
<script src=”../../scripts/jquery-壹.三.1.js”
type=”text/javascript”></script> <script> $(function () {
$(“a”).click(function (event) { alert(event.type); //获取事件类型 return
false; //阻止链接跳转 }); }) </script> </head> <body>
<a href=’ me .</a> </body>
</html> View Code

  (2)event.target 能够取得出发事件的要素

图片 11<!DOCTYPE
html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“; <html
xmlns=”; <head>
<title></title> <meta http-equiv=”Content-Type”
content=”text/html; charset=utf-8″ /> <!– 引入jQuery –>
<script src=”../../scripts/jquery-1.3.1.js”
type=”text/javascript”></script> <script> $(function () {
$(“a[href= (event) {
alert(event.target.href); //获取触发事件的<a>成分的href属性值
return false; //阻止链接跳转 }); }) </script> </head>
<body> <a href=’ me .</a>
</body> </html> View
Code

  (三)event.pageX和event.pageY 能够得到光标相对于页面的x坐标与y坐标。

图片 12<!DOCTYPE
html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“; <html
xmlns=”; <head>
<title></title> <meta http-equiv=”Content-Type”
content=”text/html; charset=utf-8″ /> <!– 引入jQuery –>
<script src=”../../scripts/jquery-1.三.一.js”
type=”text/javascript”></script> <script> $(function () {
$(“a”).click(function (event) { alert(“Current mouse position: ” +
event.pageX + “, ” + event.pageY); //获取鼠标当前相对于页面包车型地铁坐标 return
false; //阻止链接跳转 }); }) </script> </head> <body>
<a href=’ me .</a> </body>
</html> View Code

  (四)event.which
能够在鼠标单击事件中赢得鼠标的左中右键,也能够博得键盘键。

图片 13<!DOCTYPE
html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“; <html
xmlns=”; <head>
<title></title> <meta http-equiv=”Content-Type”
content=”text/html; charset=utf-8″ /> <!– 引入jQuery –>
<script src=”../../scripts/jquery-一.叁.1.js”
type=”text/javascript”></script> <script> $(function(){
$(“a”).mousedown(function(e){ alert(e.which) // 1 = 鼠标左键 left; 二 =
鼠标中键; 三 = 鼠标右键 return false;//阻止链接跳转 }) }) </script>
</head> <body> <a href=’ me
.</a> </body> </html> View Code
图片 14<!DOCTYPE
html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“; <html
xmlns=”; <head>
<title></title> <meta http-equiv=”Content-Type”
content=”text/html; charset=utf-8″ /> <!– 引入jQuery –>
<script src=”../../scripts/jquery-1.3.1.js”
type=”text/javascript”></script> <script> $(function () {
$(“input”).keyup(function (e) { alert(e.which); }) }) </script>
</head> <body> <input /> </body> </html>
View Code

  陆.移除事件

  unbind([type],[data])方法用来移除事件。

图片 15<!DOCTYPE
html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“; <html
xmlns=”; <head> <meta
http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>4-6-2</title> <style type=”text/css”> * {
margin: 0; padding: 0; } body { font-size: 13px; line-height: 130%;
padding: 60px; } p { width: 200px; background: #888; color: white;
height: 16px; } </style> <script
src=”../../scripts/jquery-1.3.1.js”
type=”text/javascript”></script> <script
type=”text/javascript”> $(function () { $(‘#btn’).bind(“click”,
function () { $(‘#test’).append(“<p>笔者的绑定函数一</p>”);
}).bind(“click”, function () {
$(‘#test’).append(“<p>小编的绑定函数2</p>”); }).bind(“click”,
function () { $(‘#test’).append(“<p>小编的绑定函数3</p>”);
}); $(‘#delAll’).click(function () { $(‘#btn’).unbind(“click”); }); })
</script> </head> <body> <button id=”btn”>
点击小编</button> <div id=”test”> </div> <button
id=”delAll”> 删除全数事件</button> </body> </html>
View Code
图片 16<!DOCTYPE
html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“; <html
xmlns=”; <head> <meta
http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>Panel</title> <style type=”text/css”> * {
margin: 0; padding: 0; } body { font-size: 13px; line-height: 130%;
padding: 60px; } p { width: 200px; background: #888; color: white;
height: 16px; } </style> <script
src=”../../scripts/jquery-1.3.1.js”
type=”text/javascript”></script> <script
type=”text/javascript”> $(function () { $(‘#btn’).bind(“click”,
myFun1 = function () {
$(‘#test’).append(“<p>小编的绑定函数壹</p>”); }).bind(“click”,
myFun贰 = function () {
$(‘#test’).append(“<p>作者的绑定函数二</p>”); }).bind(“click”,
myFun三 = function () {
$(‘#test’).append(“<p>小编的绑定函数叁</p>”); });
$(‘#delTwo’).click(function () { $(‘#btn’).unbind(“click”, myFun二);
}); }) </script> </head> <body> <button
id=”btn”> 点击笔者</button> <div id=”test”> </div>
<button id=”delTwo”> 删除第一个事件</button> </body>
</html> View Code

  one(type,[data],fn)方法能够为要素绑定处理函数,当处理函数触发二回后立马删除。

图片 17<!DOCTYPE
html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“; <html
xmlns=”; <head> <meta
http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>4-6-4</title> <style type=”text/css”> * {
margin: 0; padding: 0; } body { font-size: 13px; line-height: 130%;
padding: 60px; } p { width: 200px; background: #888; color: white;
height: 16px; } </style> <script
src=”../../scripts/jquery-1.3.1.js”
type=”text/javascript”></script> <script
type=”text/javascript”> $(function () { $(‘#btn’).one(“click”,
function () { $(‘#test’).append(“<p>作者的绑定函数一</p>”);
}).one(“click”, function () {
$(‘#test’).append(“<p>笔者的绑定函数2</p>”); }).one(“click”,
function () { $(‘#test’).append(“<p>小编的绑定函数三</p>”);
}); }) </script> </head> <body> <button
id=”btn”> 点击笔者</button> <div id=”test”> </div>
</body> </html> View
Code

  七.模拟操作

  jQuery中能够使用trigger()方法成功臣模范拟操作。

图片 18<!DOCTYPE
html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“; <html
xmlns=”; <head> <meta
http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title></title> <style type=”text/css”> * { margin:
0; padding: 0; } body { font-size: 13px; line-height: 130%; padding:
60px; } p { width: 200px; background: #888; color: white; height: 16px;
} </style> <script src=”../../scripts/jquery-1.3.1.js”
type=”text/javascript”></script> <script
type=”text/javascript”> $(function () { $(‘#btn’).bind(“click”,
function () { $(‘#test’).append(“<p>作者的绑定函数1</p>”);
}).bind(“click”, function () {
$(‘#test’).append(“<p>作者的绑定函数二</p>”); }).bind(“click”,
function () { $(‘#test’).append(“<p>作者的绑定函数三</p>”);
}); $(‘#btn’).trigger(“click”); }) </script> </head>
<body> <button id=”btn”> 点击我</button> <div
id=”test”> </div> </body> </html> View Code
图片 19<!DOCTYPE
html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“; <html
xmlns=”; <head> <meta
http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title></title> <style type=”text/css”> * { margin:
0; padding: 0; } body { font-size: 13px; line-height: 130%; padding:
60px; } p { width: 200px; background: #888; color: white; height: 16px;
} </style> <script src=”../../scripts/jquery-1.3.1.js”
type=”text/javascript”></script> <script
type=”text/javascript”> $(function () { $(‘#btn’).bind(“myClick”,
function (event, message1, message2) { $(‘#test’).append(“<p>” +
message1 + message2 + “</p>”); }); $(‘#btn’).click(function () {
$(this).trigger(“myClick”, [“作者的自定义”, “事件”]);
}).trigger(“myClick”, [“小编的自定义”, “事件”]); }) </script>
</head> <body> <button id=”btn”> 点击我</button>
<div id=”test”> </div> </body> </html> View Code

 PS:参考文献《锋利的jQuery》

详解Jquery 选择器,详解jquery选择器

1   概述

 本篇小说为穿插小说,ASP.NET MVC类别方今写了之类几篇:

  • 详解google Chrome浏览器(理论篇)
  • 详解Google Chrome浏览器(操作篇)(上)
  • 详解Google Chrome浏览器(操作篇)(下)
  • .NET 开发条件搭建
  • 详解ASP.NET MVC 路由
  • 详解ASP.NET MVC 控制器

写该篇文章首要指标是为接下去的ASP.NET MVC
种类,如页面之间传值,ADO.NET和EF,Bootstrap等打基础,本篇文章相比较基础,但正如健全,相当适合基础火速扫除文盲。

二   基本采纳器

2.1  一览表

图片 20

二.贰  示例代码

 (1)id选择器

将id为lastname成分的背景观设置为桃红

图片 21 1
<!DOCTYPE html> 2 3 <html> 4 <head> 5 <meta
name=”viewport” content=”width=device-width” /> 6 <script
src=”~/Scripts/jquery-1.10.2.js”></script> 7
<title>JQuery函数</title> 8 <script
type=”text/javascript”> 9 $(document).ready(function () { 10
$(“#lastname”).css(“background-color”, “#0000ff”); 1壹 1二 }); 一叁 1四</script> 15 </head> 1六 <body> 一7 <div
id=”lastname”>id为lastname的选项器</div> 18 </body> 19</html> View Code

(贰)类选取器

将class为intro成分的背景象设置为鲜蓝

图片 22 1
<!DOCTYPE html> 2 3 <html> 4 <head> 5 <meta
name=”viewport” content=”width=device-width” /> 6 <script
src=”~/Scripts/jquery-1.10.2.js”></script> 7
<title>JQuery函数</title> 8 <script
type=”text/javascript”> 9 $(document).ready(function () { 10
$(“.intro”).css(“background-color”, “#0000ff”); 1一 1二 }); 13 1四</script> 1伍 </head> 1六 <body> 一7 <div
class=”intro”>div采取器测试</div> 1八 <p
class=”intro”>p测试选用器</p> 1九 </body> 20 </html>
View Code

(三)成分选取器

将p成分的背景象设置为水晶绿

图片 23 1
<!DOCTYPE html> 2 3 <html> 4 <head> 5 <meta
name=”viewport” content=”width=device-width” /> 6 <script
src=”~/Scripts/jquery-1.10.2.js”></script> 7
<title>JQuery函数</title> 8 <script
type=”text/javascript”> 9 $(document).ready(function () { 10
$(“p”).css(“background-color”, “#0000ff”); 1壹 12 }); 一三 1四</script> 一5 </head> 1六 <body> 一七<p>p测试采取器</p> 18 </body> 1玖 </html> View Code

(肆)全体采纳器

遍历body下的持有因素,将其背景象设置为青黄

图片 24 1
<!DOCTYPE html> 2 3 <html> 4 <head> 5 <meta
name=”viewport” content=”width=device-width” /> 6 <script
src=”~/Scripts/jquery-1.10.2.js”></script> 7
<title>JQuery函数</title> 8 <script
type=”text/javascript”> 9 $(document).ready(function () { 10 $(“body
*”).css(“background-color”, “#0000ff”); 1① 1二 }); 一3 1四</script> 1五 </head> 1陆 <body> 17<div>选拔器测试</div> 18 <p>p成分</p> 1九</body> 20 </html> View
Code

(5)并列选择器

 将成分p和因素div背景观设置为威尼斯红

图片 25 1
<!DOCTYPE html> 2 3 <html> 4 <head> 5 <meta
name=”viewport” content=”width=device-width” /> 6 <script
src=”~/Scripts/jquery-1.10.2.js”></script> 7
<title>JQuery函数</title> 8 <script
type=”text/javascript”> 9 $(document).ready(function () { 10
$(“p,div”).css(“background-color”, “#0000ff”); 1一 1二 }); 一叁 1肆</script> 一5 </head> 1陆 <body> 一7<div>选取器测试</div> 18 <p>p成分</p> 19</body> 20 </html> View
Code

三   层次接纳器

3.1 一览表

图片 26

三.2 示例代码

(一)parent>child(直系子元素,即直接下一代成分)

安装div成分的第一代元素为span的成分的背景象为深紫灰

图片 27 1
<!DOCTYPE html> 2 3 <html> 4 <head> 5 <meta
name=”viewport” content=”width=device-width” /> 6 <script
src=”~/Scripts/jquery-1.10.2.js”></script> 7
<title>JQuery函数</title> 8 <script
type=”text/javascript”> 9 $(document).ready(function () { 10
$(“div>span”).css(“background-color”, “#0000ff”); 11 12 }); 13 14
</script> 15 </head> 16 <body> 17 <div> 18
<span>DOM树,DIV第一代</span> 19 <p> 20
<span>DOM树,第二代</span> 21 </p> 22
<span>DOM树,DIV第一代</span> 23 </div> 24
</body> 25 </html> View
Code

测试结果:

图片 28

结果分析:依照如上代码画出的DOM树如下,能够很清晰看出,DIV有四个一向孩子,即首先代span,p,span,代码中div>span,表示div下的第二手第三代span,因而,测试结果就简单理解了。

图片 29

(二)prev+next(prev成分的下贰个男士成分,等同于next()方法)

设置类为intro成分的下3个小兄弟成分背景象为藏青

图片 30 1
<!DOCTYPE html> 2 3 <html> 4 <head> 5 <meta
name=”viewport” content=”width=device-width” /> 6 <script
src=”~/Scripts/jquery-1.10.2.js”></script> 7
<title>JQuery函数</title> 8 <script
type=”text/javascript”> 9 $(document).ready(function () { 10
$(“.intro+div”).css(“background-color”, “#0000ff”); 11
//$(“.intro”).next(“div”).css(“background-color”, “#0000ff”); 12 13 });
14 15 </script> 16 </head> 17 <body> 18
<div>1</div> 19 <p class=”intro”>2</p> 20
<div>3</div> 21 <div>4</div> 22 <span
class=”item”>5</span> 23 <div>6</div> 24
</body> 25 </html> View
Code

测试结果:

图片 31

结果分析:依据如上代码画出DOM树如下图,测试结果肯定。

图片 32

(3)prev~siblings(prev元素的富有兄弟成分,等同于nextAll()方法)

 设置类为intro成分之后的有着兄弟成分为div成分的背景象为黄铜色

图片 33 1
<!DOCTYPE html> 2 3 <html> 4 <head> 5 <meta
name=”viewport” content=”width=device-width” /> 6 <script
src=”~/Scripts/jquery-1.10.2.js”></script> 7
<title>JQuery函数</title> 8 <script
type=”text/javascript”> 9 $(document).ready(function () { 10
$(“.intro~div”).css(“background-color”, “#0000ff”); 11 }); 12 13
</script> 14 </head> 15 <body> 16
<div>G0</div> 17 <div class=”intro”>G1</div> 18
<div>G2</div> 19 <span>G3</span> 20
<div>G4</div> 21 </body> 22 </html> View Code

测试结果:

图片 34

分析测试结果:依据如上代码画出DOM树如下图,测试结果肯定。

图片 35

4   过滤选取器

4.壹 基本过滤采用器

4.1.1  一览表

图片 36

四.1.贰  代码示例

(1):first(选用第3个因素)

图片 37 1
<!DOCTYPE html> 2 3 <html> 4 <head> 5 <meta
name=”viewport” content=”width=device-width” /> 6 <script
src=”~/Scripts/jquery-1.10.2.js”></script> 7
<title>JQuery函数</title> 8 <script
type=”text/javascript”> 9 $(document).ready(function () { 10
$(“span:first”).css(“background-color”, “#0000ff”); 11 }); 12 13
</script> 14 </head> 15 <body> 16
<span>G1</span> 17 <span>G2</span> 18
<span>G3</span> 19 </body> 20 </html> View Code

测试结果:

图片 38

(2):last(选用最终一个要素)

图片 39 1
<!DOCTYPE html> 2 3 <html> 4 <head> 5 <meta
name=”viewport” content=”width=device-width” /> 6 <script
src=”~/Scripts/jquery-1.10.2.js”></script> 7
<title>JQuery函数</title> 8 <script
type=”text/javascript”> 9 $(document).ready(function () { 10
$(“span:last”).css(“background-color”, “#0000ff”); 11 }); 12 13
</script> 14 </head> 15 <body> 16
<span>G1</span> 17 <span>G2</span> 18
<span>G3</span> 19 </body> 20 </html> View Code

测试结果:

图片 40

(3):not(取非成分)

图片 41 1
<!DOCTYPE html> 2 3 <html> 4 <head> 5 <meta
name=”viewport” content=”width=device-width” /> 6 <script
src=”~/Scripts/jquery-1.10.2.js”></script> 7
<title>JQuery函数</title> 8 <script
type=”text/javascript”> 9 $(document).ready(function () { 10
$(“div:not(.wrap)”).css(“background-color”, “#0000ff”); 11 }); 12 13
</script> 14 </head> 15 <body> 16
<div>G1</div> 17 <div class=”wrap”>G2</div> 18
</body> 19 </html> View
Code

只是,请小心下边包车型大巴代码:当G一所在div和G二所在div是父子关系时,G一和G贰都会变色。

图片 421
<div> 2     G1    <div class=”wrap”>G2</div> 3
</div> View Code

(四):even(索引为偶数,索引 index从0开端)

图片 43 1
<!DOCTYPE html> 2 3 <html> 4 <head> 5 <meta
name=”viewport” content=”width=device-width” /> 6 <script
src=”~/Scripts/jquery-1.10.2.js”></script> 7
<title>JQuery函数</title> 8 <script
type=”text/javascript”> 9 $(document).ready(function () { 10
$(“div:even”).css(“background-color”, “#0000ff”); 11 }); 12 13
</script> 14 </head> 15 <body> 16
<div>G1</div> 17 <div>G2</div> 18
<div>G3</div> 19 <div>G4</div> 20 </body>
21 </html> View Code

测试结果:

图片 44

(5):odd(索引为奇数,索引 index从0开端)

图片 45 1
<!DOCTYPE html> 2 3 <html> 4 <head> 5 <meta
name=”viewport” content=”width=device-width” /> 6 <script
src=”~/Scripts/jquery-1.10.2.js”></script> 7
<title>JQuery函数</title> 8 <script
type=”text/javascript”> 9 $(document).ready(function () { 10
$(“div:odd”).css(“background-color”, “#0000ff”); 11 }); 12 13
</script> 14 </head> 15 <body> 16
<div>G1</div> 17 <div>G2</div> 18
<div>G3</div> 19 <div>G4</div> 20 </body>
21 </html> View Code

测试结果:

图片 46

(6):eq(x)(取钦赐索引的要素,x为从0开首的目录)

设置索引为二的div成分背景为松石绿

图片 47 1
<!DOCTYPE html> 2 3 <html> 4 <head> 5 <meta
name=”viewport” content=”width=device-width” /> 6 <script
src=”~/Scripts/jquery-1.10.2.js”></script> 7
<title>JQuery函数</title> 8 <script
type=”text/javascript”> 9 $(document).ready(function () { 10
$(“div:eq(2)”).css(“background-color”, “#0000ff”); 11 }); 12 13
</script> 14 </head> 15 <body> 16
<div>G1</div> 17 <div>G2</div> 18
<div>G3</div> 19 <div>G4</div> 20 </body>
21 </html> View Code

测试结果:

图片 48

(七):lt(x))(取小于钦命索引的因素,x为从0初阶的目录)

图片 49 1
<!DOCTYPE html> 2 3 <html> 4 <head> 5 <meta
name=”viewport” content=”width=device-width” /> 6 <script
src=”~/Scripts/jquery-1.10.2.js”></script> 7
<title>JQuery函数</title> 8 <script
type=”text/javascript”> 9 $(document).ready(function () { 10
$(“div:lt(2)”).css(“background-color”, “#0000ff”); 11 }); 12 13
</script> 14 </head> 15 <body> 16
<div>G1</div> 17 <div>G2</div> 18
<div>G3</div> 19 <div>G4</div> 20 </body>
21 </html> View Code

测试结果:

图片 50

(八):gt(x))(取大于钦命索引的成分,x为从0先导的目录)

图片 51 1
<!DOCTYPE html> 2 3 <html> 4 <head> 5 <meta
name=”viewport” content=”width=device-width” /> 6 <script
src=”~/Scripts/jquery-1.10.2.js”></script> 7
<title>JQuery函数</title> 8 <script
type=”text/javascript”> 9 $(document).ready(function () { 10
$(“div:gt(2)”).css(“background-color”, “#0000ff”); 11 }); 12 13
</script> 14 </head> 15 <body> 16
<div>G1</div> 17 <div>G2</div> 18
<div>G3</div> 19 <div>G4</div> 20 </body>
21 </html> View Code

测试结果:

图片 52

(八):header(取h1-h陆题目成分)

图片 53 1
<!DOCTYPE html> 2 3 <html> 4 <head> 5 <meta
name=”viewport” content=”width=device-width” /> 6 <script
src=”~/Scripts/jquery-1.10.2.js”></script> 7
<title>JQuery函数</title> 8 <script
type=”text/javascript”> 9 $(document).ready(function () { 10
$(“:header”).css(“background-color”, “#0000ff”); 11 }); 12 13
</script> 14 </head> 15 <body> 16
<h1>测试H1标题</h1> 17 <div>G1</div> 18
<div>G2</div> 19 <div>G3</div> 20
<h2>测试h2标题</h2> 21 <h3>测试h3标题</h3> 22
<h4>测试h4标题</h4> 23 <div>G4</div> 24
<h5>测试h5标题</h5> 25 <h6>测试h6标题</h6> 26
</body> 27 </html> View
Code

测试结果:

图片 54

(九):animated(全数动画成分)

图片 55 1
<!DOCTYPE html> 2 3 <html> 4 <head> 5 <meta
name=”viewport” content=”width=device-width” /> 6 <script
src=”~/Scripts/jquery-1.10.2.js”></script> 7
<title>JQuery函数</title> 8 <script
type=”text/javascript”> 9 $(document).ready(function () { 10 function
aniDiv() { 11 $(“#box”).animate({ width: 300 }, “slow”); 12
$(“#box”).animate({ width: 100 }, “slow”, aniDiv); 13 } 14 aniDiv(); 15
$(“.btn1”).click(function () { 16 $(“:animated”).css(“background-color”,
“#0000ff”); 17 }); 18 }); 19 20 </script> 21 <style> 22 div
{ 23 background: #98bf21; 24 height: 40px; 25 width: 100px; 26
position: relative; 27 margin-bottom: 5px; 28 } 29 </style> 30
</head> 31 <body> 32 <div></div> 33 <div
id=”box”></div> 34 <div></div> 35 <button
class=”btn1″>Mark animated element</button> 36 </body> 37
</html> View Code

测试结果:

 图片 56

四.二 内容过滤采用器

4.2.1 一览表

图片 57

四.贰.二 示例代码

(1):contains(text)(取包蕴text文本的成分)

图片 58 1
<!DOCTYPE html> 2 3 <html> 4 <head> 5 <meta
name=”viewport” content=”width=device-width” /> 6 <script
src=”~/Scripts/jquery-1.10.2.js”></script> 7
<title>JQuery函数</title> 8 <script
type=”text/javascript”> 9 $(document).ready(function () { 10
$(‘div:contains(“G2”)’).css(“background-color”, “#0000ff”); 11 }); 12
13 </script> 14 15 </head> 16 <body> 17
<div>G1</div> 18 <div>G2</div> 19
<div>G3</div> 20 </body> 21 </html> View Code

测试结果:

图片 59

(二):empty(取不含有子成分或文本为空的要素)

图片 60 1
<!DOCTYPE html> 2 3 <html> 4 <head> 5 <meta
name=”viewport” content=”width=device-width” /> 6 <script
src=”~/Scripts/jquery-一.十.贰.js”></script> 7<title>JQuery函数</title> 8 <script
type=”text/javascript”> 九 $(document).ready(function () { 10$(‘div:empty’).html(‘没有内容’); 1一 }); 12 一三 </script> 14 一5</head> 16 <body> 1柒 <div>G1</div> 1八<div>G2</div> 1⑨ <div>G3</div> 20
<div></div> 贰一 </body> 22 </html> View Code

测试结果:

图片 61

(三) :has(selector)(取选取器匹配的因素)

即使span不是div的直系子成分,也会生效

图片 62 1
<!DOCTYPE html> 2 3 <html> 4 <head> 5 <meta
name=”viewport” content=”width=device-width” /> 6 <script
src=”~/Scripts/jquery-一.十.二.js”></script> 7<title>JQuery函数</title> 八 <script
type=”text/javascript”> 玖 $(document).ready(function () { 十 //
为含有span成分的div添加边框 11 $(‘div:has(span)’).css(‘border’, ‘一px
solid #000’); 12 }); 13 14 </script> 15 16 </head> 17
<body> 18 <div> 19 <h2> 20
A     <span>B</span> 21 </h2> 22 </div> 23
</body> 24 </html> View
Code

测试结果:

图片 63

(四):parent(取包罗子成分或文本的要素)

图片 64 1
<!DOCTYPE html> 2 3 <html> 4 <head> 5 <meta
name=”viewport” content=”width=device-width” /> 6 <script
src=”~/Scripts/jquery-1.10.2.js”></script> 7
<title>JQuery函数</title> 8 <script
type=”text/javascript”> 9 $(document).ready(function () { 10 $(‘ol
li:parent’).css(‘border’, ‘1px solid #000’); 11 }); 12 13
</script> 14 15 </head> 16 <body> 17 <ol> 18
<li></li> 19 <li>A</li> 20 <li></li>
21 <li>D</li> 22 </ol> 23 </body> 24
</html> View Code

测试结果:

图片 65

肆.3 可知性过滤选拔器

4.3.1 一览表

图片 66

四.三.二 示例代码

(一):hidden(取不可知的成分)

匹配display:none,<input type=”hidden”
/>,visibility:hidden,capacity:0元素

图片 67 1
<!DOCTYPE html> 2 3 <html> 4 <head> 5 <meta
name=”viewport” content=”width=device-width” /> 6 <script
src=”~/Scripts/jquery-1.10.2.js”></script> 7
<title>JQuery函数</title> 8 <script
type=”text/javascript”> 9 $(document).ready(function () { 10
$(‘div:hidden’).show(500); 11 alert($(‘input:hidden’).val()); 12 }); 13
</script> 14 <style type=”text/css”> 15 div         16 { 17
margin: 10px; 18 width: 200px; 19 height: 40px; 20 border: 1px solid
#FF0000; 21 display:block; 22 } 23 24 .hid-1         25 { 26 display:
none; 27 } 28 29 .hid-2         30 { 31 visibility: hidden; 32 } 33 34
</style> 35 </head> 36 <body> 37 <div
class=”hid-1″>display: none</div> 38 <div
class=”hid-2″>visibility: hidden</div> 39 <input
type=”hidden” value=”hello” /> 40 </body> 41 </html>
View Code

测试结果:

图片 68

(二):visible(取可见的因素)

图片 69 1
<!DOCTYPE html> 2 3 <html> 4 <head> 5 <meta
name=”viewport” content=”width=device-width” /> 6 <script
src=”~/Scripts/jquery-1.10.2.js”></script> 7
<title>JQuery函数</title> 8 <script
type=”text/javascript”> 9 $(document).ready(function () { 10
$(‘div:visible’).css(“background-color”, “#0000ff”); 11 }); 12 13
</script> 14 15 </head> 16 <body> 17 <div
style=”display:none”>G1</div> 18 <div>G2</div> 19
<div style=”display:none”>G3</div> 20
<div>G4</div> 21 22 </body> 23 </html> 24 25 26
View Code

测试结果:

图片 70

4.4 属性过滤采用器

4.4.1 一览表

图片 71

四.肆.二 代码示例

(1)[attribute](取拥有attribute属性的因素)

图片 72 1
<!DOCTYPE html> 2 3 <html> 4 <head> 5 <meta
name=”viewport” content=”width=device-width” /> 6 <script
src=”~/Scripts/jquery-1.10.2.js”></script> 7
<title>JQuery函数</title> 8 <script
type=”text/javascript”> 9 $(document).ready(function () { 10
$(‘div[class]’).css(“background-color”, “#0000ff”); 11 }); 12 13
</script> 14 15 </head> 16 <body> 17
<div>G1</div> 18 <div>G2</div> 19
<div>G3</div> 20 <div class=”div4″>G4</div> 21
22 </body> 23 </html> 24 25 26 View Code

测试结果:

图片 73

(2)[attribute = value](取attribute属性值等于value)

图片 74 1
<!DOCTYPE html> 2 3 <html> 4 <head> 5 <meta
name=”viewport” content=”width=device-width” /> 6 <script
src=”~/Scripts/jquery-1.10.2.js”></script> 7
<title>JQuery函数</title> 8 <script
type=”text/javascript”> 9 $(document).ready(function () { 10
$(‘div[class=div3]’).css(“background-color”, “#0000ff”); 11 }); 12 13
</script> 14 15 </head> 16 <body> 17
<div>G1</div> 18 <div>G2</div> 19 <div
class=”div3″>G3</div> 20 <div class=”div4″>G4</div>
21 22 </body> 23 </html> 24 25 26 View Code

测试结果:

图片 75

(3) [attribute != value](取attribute属性值不对等value的要素)

图片 76 1
<!DOCTYPE html> 2 3 <html> 4 <head> 5 <meta
name=”viewport” content=”width=device-width” /> 6 <script
src=”~/Scripts/jquery-1.10.2.js”></script> 7
<title>JQuery函数</title> 8 <script
type=”text/javascript”> 9 $(document).ready(function () { 10
$(‘div[class!=div3]’).css(“background-color”, “#0000ff”); 11 }); 12
13 </script> 14 15 </head> 16 <body> 17
<div>G1</div> 18 <div>G2</div> 19 <div
class=”div3″>G3</div> 20 <div class=”div4″>G4</div>
21 22 </body> 23 </html> 24 25 26 View Code

测试结果:

图片 77

(4)[attribute $= value](attribute属性值以value截止)

图片 78 1
<!DOCTYPE html> 2 3 <html> 4 <head> 5 <meta
name=”viewport” content=”width=device-width” /> 6 <script
src=”~/Scripts/jquery-1.10.2.js”></script> 7
<title>JQuery函数</title> 8 <script
type=”text/javascript”> 9 $(document).ready(function () { 10
$(‘[id$=div]’).css(“background-color”, “#0000ff”); 11 }); 12 13
</script> 14 15 </head> 16 <body> 17 <div
id=”first_div”>G1</div> 18 <div
id=”second_div”>G2</div> 19 <div class=”div3″
title=”3div”>G3</div> 20 <div class=”div4″>G4</div>
21 22 </body> 23 </html> View Code

测试结果:

图片 79

(5))[attribute^= value](attribute属性值以value开端)

图片 80 1
<!DOCTYPE html> 2 3 <html> 4 <head> 5 <meta
name=”viewport” content=”width=device-width” /> 6 <script
src=”~/Scripts/jquery-1.10.2.js”></script> 7
<title>JQuery函数</title> 8 <script
type=”text/javascript”> 9 $(document).ready(function () { 10
$(‘[id^=first]’).css(“background-color”, “#0000ff”); 11 }); 12 13
</script> 14 15 </head> 16 <body> 17 <div
id=”first_div”>G1</div> 18 <div
id=”second_div”>G2</div> 19 <div class=”div3″
title=”3div”>G3</div> 20 <div class=”div4″>G4</div>
21 22 </body> 23 </html> 24 25 26 View Code

测试结果:

图片 81

(6)[attribute *= value](attribute属性值包蕴value值)

图片 82 1
<!DOCTYPE html> 2 3 <html> 4 <head> 5 <meta
name=”viewport” content=”width=device-width” /> 6 <script
src=”~/Scripts/jquery-1.10.2.js”></script> 7
<title>JQuery函数</title> 8 <script
type=”text/javascript”> 9 $(document).ready(function () { 10
$(‘[id*=first]’).css(“background-color”, “#0000ff”); 11 }); 12 13
</script> 14 15 </head> 16 <body> 17 <div
id=”first_div”>G1</div> 18 <div
id=”second_div”>G2</div> 19 <div class=”div3″
title=”3div”>G3</div> 20 <div class=”div4″>G4</div>
21 22 </body> 23 </html> View Code

测试结果:

图片 83

申明:在品质选取器中,^$符号和正则表明式的起来终结符号表示的意思是同样的,*混淆匹配,类似于sql中的like
‘%str%’。

(7)[selector1][selector2](复合型属性过滤器,同时满意四个规格)

图片 84 1
<!DOCTYPE html> 2 3 <html> 4 <head> 5 <meta
name=”viewport” content=”width=device-width” /> 6 <script
src=”~/Scripts/jquery-1.10.2.js”></script> 7
<title>JQuery函数</title> 8 <script
type=”text/javascript”> 9 $(document).ready(function () { 10
$(‘div[class=div3][title=3div]’).css(“background-color”,
“#0000ff”); 11 }); 12 13 </script> 14 15 </head> 16
<body> 17 <div>G1</div> 18 <div>G2</div>
19 <div class=”div3″ title=”3div”>G3</div> 20 <div
class=”div4″>G4</div> 21 22 </body> 23 </html> 24
25 26 View Code

测试结果:

图片 85

四.5 子成分过滤选拔器

4.5.1 一览表

图片 86

4.五.二 代码示例

(一)first-child(表示格外的第三个成分)和last-child(表示相当的末段一个子元素)

 须要大家瞩指标是,:fisrst和:last再次来到的都以单个成分,而:first-child和:last-child重返的都以集合成分。举个
例子:div:first再次回到的是整套DOM文书档案中率先个div成分,而div:first-child是回去全体div元素下的第一个成分合并后的集
合。

图片 87 1
<!DOCTYPE html> 2 3 <html> 4 <head> 5 <meta
name=”viewport” content=”width=device-width” /> 6 <script
src=”~/Scripts/jquery-1.10.2.js”></script> 7
<title>JQuery函数</title> 8 <script
type=”text/javascript”> 9 $(document).ready(function () { 10
$(“div:first-child”).css(“background-color”, “#B2E0FF”); 11
$(“div:last-child”).css(“background-color”, “red”); 12 }); 13
</script> 14 </head> 15 <body> 16 <div> 17
<div>1</div> 18 <div>2</div> 19
<p>3</p> 20 </div> 21 <div>4</div> 22
<div>last</div> 23 </body> 24 </html> View Code

测试结果:

图片 88

(3)only-child(当有个别成分有且仅有一个子成分时,:only-child才会立见成效)

图片 89 1
<!DOCTYPE html> 2 3 <html> 4 <head> 5 <meta
name=”viewport” content=”width=device-width” /> 6 <script
src=”~/Scripts/jquery-1.10.2.js”></script> 7
<title>JQuery函数</title> 8 <script
type=”text/javascript”> 9 $(document).ready(function () { 10
$(“div:only-child”).css(“background-color”, “red”); 11 }); 12
</script> 13 </head> 14 <body> 15 <div> 16
<div>1</div> 17 <div>2</div> 18
<p>3</p> 19 </div> 20 <div>4</div> 21
<div>last 22 <div>ddd</div> 23 </div> 24
</body> 25 </html> View
Code

测试结果:

图片 90

(4)nth-child

见到那一个就想起英文单词里的,fourth, fifth,
sixth……,nth表示第n个,:nth-child就象征第n个child元素。要留意的是,这儿的n不像eq(x)、gt(x)或lt(x)是从
0开端的,它是从1从头的,英文里好像也并未有zeroth那样的序号词吗。

:nth-child有三种用法:

1) :nth-child(x),获取第x个子成分
二)
:nth-child(even)和:nth-child(odd),从1上马,获取第偶数个要素或第奇数个成分

三) :nth-child(xn+y),x>=0,y>=0。例如x = 三, y =
0时正是3n,表示取第一n个因素(n>=0)。实际上xn+y是地方二种的通项式。(当x=0,y>=0时,等同于:hth-
child(x);当x=2,y=0时,等同于nth-child(even);当x=二,y=壹时,等同于:nth-child(odd))

四.六 表单对象属性过滤选拔器

4.6.1 一览表

图片 91

四.陆.二 代码示例

(一):enabled和:disabled(取可用或不可用成分)

:enabled和:diabled的匹配范围包罗input, select, textarea

图片 92 1
<!DOCTYPE html> 2 3 <html> 4 <head> 5 <meta
name=”viewport” content=”width=device-width” /> 6 <script
src=”~/Scripts/jquery-1.10.2.js”></script> 7
<title>JQuery函数</title> 8 <script
type=”text/javascript”> 9 $(document).ready(function () { 10
$(‘:enabled’).css(‘border’, ‘1px solid #FF0000’); 11
$(‘:disabled’).css(‘border’, ‘1px solid #0000FF’); 1二 }); 一叁 14</script> 一伍 1陆 </head> 壹7 <body> 18 <div> 1玖<input type=”text” value=”可用的文本框” /> 20 </div> 21<div> 22 <input type=”text” disabled=”disabled”
value=”不可用的文本框” /> 贰三 </div> 二四 <div> 二五<textarea disabled=”disabled”>不可用的文本域</textarea> 26</div> 二7 <div> 2八 <select disabled=”disabled”> 29<option>English</option> 30
<option>简体汉语</option> 3壹 </select> 32 </div>
3三 </body> 3四 </html> View Code

测试结果:

图片 93

(二):checked(取选中的单选框或复选框成分)

图片 94 1
<!DOCTYPE html> 2 3 <html> 4 <head> 5 <meta
name=”viewport” content=”width=device-width” /> 6 <script
src=”~/Scripts/jquery-1.10.2.js”></script> 7
<title>JQuery函数</title> 8 <script
type=”text/javascript”> 9 $(document).ready(function () { 10
$(“.btn1”).click(function () { 11 $(“:checked”).hide(); 12 }); 13 }); 14
</script> 15 16 </head> 17 <body> 18 <input
type=”radio” name=”sex” value=”male” checked=”checked” /> Male 19
<br /> 20 <input type=”radio” name=”sex” value=”female” />
Female 21 <br /> 22 I have a bike: 23 <input type=”checkbox”
name=”vehicle” value=”Bike” /> 24 <br /> 25 I have a car: 26
<input type=”checkbox” name=”vehicle” value=”Car” checked=”checked”
/> 27 <br /> 28 I have an airplane: 29 <input
type=”checkbox” name=”vehicle” value=”Airplane” /> 30 <button
class=”btn1″>Hide Checked Options</button> 31 32 </body>
33 </html> View Code

(三):selected(取下拉列表被入选的要素)

图片 95 1
<html> 2 <head> 3 <script type=”text/javascript”
src=”/jquery/jquery.js”></script> 4 <script
type=”text/javascript”> 5 $(document).ready(function(){ 6
$(“.btn1”).click(function(){ 7 $(“:selected”).hide(); 8 }); 9 }); 10
</script> 11 </head> 12 <body> 13 14 <select
multiple=”multiple”> 15 <option>Volvo</option> 16
<option selected=”selected”>Saab</option> 17
<option>Mercedes</option> 18
<option>Audi</option> 19 </select> 20 <br /> 21
<button class=”btn1″>Hide Selected</button> 22 </body>
23 </html> View Code

5   表单选择器

5.1 一览表

图片 96

5.2 测试代码

(1):input()(选择具有input成分)

图片 97 1
<!DOCTYPE html> 2 3 <html> 4 <head> 5 <meta
name=”viewport” content=”width=device-width” /> 6 <script
src=”~/Scripts/jquery-1.10.2.js”></script> 7
<title>JQuery函数</title> 8 <script
type=”text/javascript”> 9 $(document).ready(function () { 10
$(“:input”).css(“background-color”, “#B2E0FF”); 11 }); 12
</script> 13 </head> 14 <body> 15 <form
action=””> 16 Name: <input type=”text” name=”user” /> 17 <br
/> 18 Password: <input type=”password” name=”password” /> 19
<br /> 20 <button type=”button”>Useless
Button</button> 21 <input type=”button” value=”Another useless
button” /> 22 <br /> 23 <input type=”reset” value=”Reset”
/> 24 <input type=”submit” value=”Submit” /> 25 <br /> 26
</form> 27 </body> 28 </html> View Code

测试结果:

图片 98

(二):text(选取全数text成分)

图片 99 1
<!DOCTYPE html> 2 3 <html> 4 <head> 5 <meta
name=”viewport” content=”width=device-width” /> 6 <script
src=”~/Scripts/jquery-1.10.2.js”></script> 7
<title>JQuery函数</title> 8 <script
type=”text/javascript”> 9 $(document).ready(function () { 10
$(“:text”).css(“background-color”, “#B2E0FF”); 11 }); 12
</script> 13 </head> 14 <body> 15 <form
action=””> 16 Name: <input type=”text” name=”user” /> 17 <br
/> 18 Password: <input type=”password” name=”password” /> 19
<br /> 20 <button type=”button”>Useless
Button</button> 21 <input type=”button” value=”Another useless
button” /> 22 <br /> 23 <input type=”reset” value=”Reset”
/> 24 <input type=”submit” value=”Submit” /> 25 <br /> 26
</form> 27 </body> 28 </html> View Code

测试结果:

图片 100

(3):select和:button

(四)别的表单成分相比较不难,在此不列举。

六   参考文献

【01】

【02】

【03】

【04】

 

选取器,详解jquery接纳器 一 概述
本篇小说为穿插文章,ASP.NET MVC种类近日写了之类几篇: 详解google
Chrome浏览器(理论篇) 详解…

 

 

jquery 事件中的事件难点

试一下在tr的轩然大波里加三个论断,看<a>有未有主旨.有就再次回到.
 

jQuery中的事件,第伍章jQuery事件 1.加载DOM
jQuery中,在$(document).ready()方法内注册的轩然大波,只要DOM就绪就会被实践,此时恐怕元素的关…

切切实实源码地址  

那边注意的是:

jquery中的事件 通过prepend添加的内容能够得到匹配事件不

你好!
壹.
对于prepend()添加的成分,大概动态变化的因素,一般选择live()进行事件钦命;二.
对于成分的toggle()事件,使用live()绑定事件时,能够由此先为其钦赐click()事件,然后在click()事件中安装该因素的toggle()事件,最终只要自动触发3回click()事件就能够了。那么些历程差不离是那般的:live()—>钦赐click()事件—>实现该因素的toggle()事件的逻辑(此时click()事件不能触发toggle()中的任何函数)—>trigger(“click”),触发toggle()中的函数。
$(“#list .message input”).live(“click”,function(){ $(this).toggle(
function(){
$(this).parent(this).after(“<div>评论列表</div>”); },
function(){ $(this).parent(this).next(this).remove(); }
).trigger(‘click’);});
 

 

图片 101

<body>
  <div id=”w”>
    <div id=”content”>
      <h1>World Currencies Autocomplete Search</h1>
      <p>Just start typing and results will be supplied from the
JavaScript. Check out <a
href=”
Autocomplete</a> on Github.</a></p>
      
      <div id=”searchfield”>
        <form><input type=”text” name=”currency”
class=”biginput” id=”autocomplete”></form>
      </div><!– @end #searchfield –>
      
      <div id=”outputbox”>
        <p id=”outputcontent”>Choose a currency and the results
will display here.</p>
      </div>
    </div><!– @end #content –>
  </div><!– @end #w –>
</body>
</html>

[java] view
plain
copy

源码如下:

  1. <%@ page language=”java” import=”java.util.*” contentType=”text/html; charset=utf-8″%>  
  2. <%  
  3.    String path = request.getContextPath();  
  4.    String basePath = request.getScheme()+”://”+request.getServerName()+”:”+request.getServerPort()+path+”/”;  
  5. %>  
  6. <html>  
  7.     <head>  
  8.         <!– Page title –>  
  9.         <title>imooc – Login</title>  
  10.         <!– End of Page title –>  
  11.         <!– Libraries –>  
  12.         <link type=”text/css” href=”css/login.css” rel=”stylesheet” />      
  13.         <link type=”text/css” href=”css/smoothness/jquery-ui-1.7.2.custom.html” rel=”stylesheet” />     
  14.         <script type=”text/javascript” src=”js/jquery-1.3.2.min.js”></script>  
  15.         <script type=”text/javascript” src=”js/easyTooltip.js”></script>  
  16.         <script type=”text/javascript” src=”js/jquery-ui-1.7.2.custom.min.js”></script>  
  17.         <!– End of Libraries –>   
  18.     </head>  
  19.     <body>  
  20.     <div id=”container”>  
  21.         <div class=”logo”>  
  22.             <a href=”#”><img src=”logo.png” alt=”” /></a>  
  23.         </div>  
  24.         <div id=”box”>  
  25.             <form action=”dologin.jsp” method=”post”>  
  26.             <p class=”main”>  
  27.                 <label>用户名: </label>  
  28.                 <input name=”username” value=”” />   
  29.                 <label>密码: </label>  
  30.                 <input type=”password” name=”password” value=””>    
  31.             </p>  
  32.             <p class=”space”>  
  33.                 <input type=”submit” value=”登录” class=”login” style=”cursor: pointer;”/>  
  34.             </p>  
  35.             </form>  
  36.         </div>  
  37.     </div>  
  38.     </body>  
  39. </html>  

发表评论

电子邮件地址不会被公开。 必填项已用*标注