菜单

澳门皇家赌场jsp完成用户登陆

2019年4月20日 - 皇家赌场系统

近日用nodeclub完成股票的输入关键字自动补全股票新闻举行查找成效,原先用jQuery-ui,结果jQuery-ui库太大,所以思量用任何插件,最后挑选使用autocomplete.js,控件轻巧用着方便。留下记录

登陆分界面 login.jsp:

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

  1.加载DOM

  jQuery中,在$(document).ready()方法内注册的风云,只要DOM就绪就会被施行,此时说不定成分的涉嫌文件未下载完。

  jQuery中的
load()方法,会在要素的onload事件中绑定二个处理函数。比方$(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”>
<h伍 class=”head”>什么是jQuery?</h五> <div
class=”content”>
jQuery是继Prototype之后又2个绝妙的JavaScript库,它是一个由 John Resig
创设于二零零六年八月的开源项目。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”>
<h伍 class=”head”>什么是jQuery?</h5> <div
class=”content”>
jQuery是继Prototype之后又2个大好的JavaScript库,它是3个由 John Resig
创设于200陆年11月的开源项目。jQuery依据简洁的语法和跨平台的兼容性,相当大地简化了JavaScript开拓人员遍历HTML文书档案、操作DOM、处管事人件、施行动画和付出Ajax。它特有而又优雅的代码风格退换了JavaScript工程师的企图思路和编写程序的点子。
</div> </div> </body> </html> View Code

  叁.合成事件

  jQuery中有2个合成事件,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
创立于2007年11月的开源项目。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”> <h五class=”head”>什么是jQuery?</h五> <div class=”content”>
jQuery是继Prototype之后又1个优异的JavaScript库,它是二个由 约翰 Resig
成立于2007年5月的开源项目。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: 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);
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: 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); 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

  (二)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

  (3)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

  (4)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-一.三.一.js”
type=”text/javascript”></script> <script> $(function(){
$(“a”).mousedown(function(e){ alert(e.which) // 一 = 鼠标左键 left; 2 =
鼠标中键; 3 = 鼠标右键 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

  6.移除事件

  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>作者的绑定函数三</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”> 删除第2个事件</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>笔者的绑定函数1</p>”);
}).one(“click”, function () {
$(‘#test’).append(“<p>笔者的绑定函数2</p>”); }).one(“click”,
function () { $(‘#test’).append(“<p>作者的绑定函数3</p>”);
}); }) </script> </head> <body> <button
id=”btn”> 点击小编</button> <div id=”test”> </div>
</body> </html> View
Code

  7.效仿操作

  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>笔者的绑定函数一</p>”);
}).bind(“click”, function () {
$(‘#test’).append(“<p>小编的绑定函数2</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种类近期写了之类几篇:

写该篇作品首要目标是为接下去的ASP.NET MVC
类别,如页面之间传值,ADO.NET和EF,Bootstrap等打基础,本篇小说比较基础,但正如完善,万分适合基础急速扫除文盲。

二   基本采用器

2.1  一览表

澳门皇家赌场 20

二.2  示例代码

 (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贰 }); 一三 14</script> 一五 </head> 1陆 <body> 一柒 <div
id=”lastname”>id为lastname的选拔器</div> 1八 </body> 1九</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”); 11 1贰 }); 13 14</script> 一5 </head> 16 <body> 一7 <div
class=”intro”>div选取器测试</div> 1捌 <p
class=”intro”>p测试选用器</p> 19 </body> 20 </html>
View Code

(3)成分选拔器

将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”); 11 1二 }); 1叁 14</script> 一5 </head> 1陆 <body> 壹七<p>p测试采纳器</p> 1捌 </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”); 11 1二 }); 1三 14</script> 一伍 </head> 1陆 <body> 一柒<div>选拔器测试</div> 1八 <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一 12 }); 一三 14</script> 一5 </head> 1陆 <body> 壹7<div>接纳器测试</div> 1八 <p>p成分</p> 19</body> 20 </html> View
Code

三   档期的顺序采取器

3.1 一览表

澳门皇家赌场 26

三.二 示例代码

(一)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下的第一手第3代span,因而,测试结果就轻巧通晓了。

澳门皇家赌场 29

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

安装类为intro成分的下2个小兄弟成分背景观为石黄

澳门皇家赌场 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.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(选择最终3个因素)

澳门皇家赌场 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

可是,请留意下边包车型大巴代码:当G1所在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

(六):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

(7):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

(8):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(取h一-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.二 内容过滤选拔器

4.2.1 一览表

澳门皇家赌场 57

四.二.二 示例代码

(一):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-壹.10.二.js”></script> 柒<title>JQuery函数</title> 八 <script
type=”text/javascript”> 九 $(document).ready(function () { 10$(‘div:empty’).html(‘未有内容’); 1一 }); 12 一三 </script> 1四 一五</head> 1六 <body> 17 <div>G1</div> 1八<div>G2</div> 1九 <div>G三</div> 20
<div></div> 二一 </body> 2二 </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-一.10.二.js”></script> 柒<title>JQuery函数</title> 八 <script
type=”text/javascript”> 玖 $(document).ready(function () { 10 //
为含有span成分的div增多边框 1一 $(‘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

4.叁 可知性过滤选择器

4.3.1 一览表

澳门皇家赌场 66

四.三.2 示例代码

(壹):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.1 一览表

澳门皇家赌场 71

4.四.二 代码示例

(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

四.五 子成分过滤选取器

4.5.1 一览表

澳门皇家赌场 86

4.伍.二 代码示例

(1)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

(三)only-child(当有个别元素有且仅有1个子元素时,: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先导的,它是从一初始的,英文里好像也并未zeroth那样的序号词吗。

:nth-child有二种用法:

1) :nth-child(x),获取第x个子成分
2)
:nth-child(even)和:nth-child(odd),从一始发,获取第偶数个因素或第奇数个要素

3) :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=二,y=0时,等同于nth-child(even);当x=二,y=一时,等同于:nth-child(odd))

四.6 表单对象属性过滤接纳器

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二 }); 一三 1四</script> 一伍 1陆 </head> 一7 <body> 1八 <div> 1玖<input type=”text” value=”可用的文本框” /> 20 </div> 二1<div> 22 <input type=”text” disabled=”disabled”
value=”不可用的文本框” /> 贰三 </div> 二4 <div> 25<textarea disabled=”disabled”>不可用的文本域</textarea> 二陆</div> 27 <div> 2八 <select disabled=”disabled”> 2玖<option>English</option> 30
<option>简体汉语</option> 3一 </select> 3二 </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

(3):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.1 一览表

澳门皇家赌场 96

5.二 测试代码

(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中的事件 通过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’);});
 

 

[java] view
plain copy

jquery 事件中的事件难点

试一下在tr的轩然大波里加2个论断,看<a>有没有核心.有就再次来到.
 

jQuery中的事件,第伍章jQuery事件 一.加载DOM
jQuery中,在$(document).ready()方法内注册的事件,只要DOM就绪就会被实践,此时大概成分的关…

 

 

<!doctype html>
<html lang=”en-US”>
<head>
  <meta http-equiv=”Content-Type”
content=”text/html;charset=utf-8″>
  <title>Input Autocomplete Suggestions Demo</title>
  <link rel=”stylesheet” type=”text/css” media=”all”
href=”style.css”>
  <script type=”text/javascript”
src=”js/codedata.js”></script>
  <script type=”text/javascript”
src=”js/jquery-1.9.1.min.js”></script>
  <script type=”text/javascript”
src=”js/jquery.autocomplete.min.js”></script>
  <script type=”text/javascript”
src=”js/currency-autocomplete.js”></script>
</head>

  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>  

<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>

对登入的响应 dologin.jsp:

相关文章

发表评论

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

网站地图xml地图