在JQuery中根据id获取控件,如果输入id错误是不报错的。

必要时可以通过写判断语句进行判断是否id写错

 <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>JQuery</title>
<style type="text/css">
.warning {
background-color:yellow;
}
</style>
<script src="js/jquery-1.11.1.min.js"type="text/javascript"></script>
<script type="text/javascript">
// $(function(){$('#btn').mouseover(function () { alert("鼠标在我上面!"); })})
//这里的id如果错误就不会报错。可以自己写出控制是否报错
$(function () {
var elements = $('#btn');
if (elements.length <= 0) {
alert("报错");
return;
}
elements.mouseover(function () { alert('鼠标在我上面');});
})
</script>
</head>
<body bgcolor="blue">
<input value="点击"type="button" id="btn"/>
</body>
</html>

.next方法用于获取本节点后面第一个同辈的节点。

意思是与本节点在同一层次级别中的下一个节点对应的值

所以说next就是指向下一个。(这里面用到的this是一个dom对象,需要转换成jquery对象)

 <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>JQuery</title>
<script src="js/jquery-1.11.1.min.js"type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('p').click(function () { alert($(this).next().text()); });
//注意这里this是dom对象,要强制转换成jquery对象
})
</script>
</head>
<body bgcolor="blue">
<p>aa</p>
<p>bb</p>
<div>div</div>
<p>cc</p>
<p>dd</p>
</body>
</html>

nextAll()是指本节点后面所有的,方法中还可以加入参数,用来查找哦后面所有相应参数对应的

 <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>JQuery</title>
<script src="js/jquery-1.11.1.min.js"type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('p').click(function () { alert($(this).nextAll().text()); });
//nextAll('div')
//注意这里this是dom对象,要强制转换成jquery对象
})
</script>
</head>
<body bgcolor="blue">
<p>aa</p>
<p>bb</p>
<div>div</div>
<p>cc</p>
<p>dd</p>
</body>
</html>

《注意是隐式迭代》

 <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>JQuery</title>
<script src="js/jquery-1.11.1.min.js"type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('p').click(function () { $(this).nextAll('p').css("background","yellow"); });
//nextAll('div')
//注意这里this是dom对象,要强制转换成jquery对象
})
$(function () { $('table td').css("font-size", "60px"); })
$(function () {
$('table td').mouseover(function () {
$('table td').css("color", "red");
$(this).nextAll('td').css("color", "black"); })
})
</script>
</head>
<body bgcolor="blue">
<p>aa</p>
<p>bb</p>
<div>div</div>
<p>cc</p>
<p>dd</p>
<table>
<tr>
<td>★</td>
<td>★</td>
<td>★</td>
<td>★</td>
<td>★</td>
</tr>
</table>
</body>
</html>

siblings()获取所有同辈元素

 <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>JQuery</title>
<script src="js/jquery-1.11.1.min.js"type="text/javascript"></script>
<script type="text/javascript">
$(function () { $('table td').css("font-size", "60px"); })
$(function () {
$('td').click(function () {
$(this).css("background", "red");
$(this).siblings("td").css("background","blue");
})
})
</script>
</head>
<body bgcolor="blue">
<table>
<tr>
<td>★</td>
<td>★</td>
<td>★</td>
<td>★</td>
<td>★</td>
</tr>
</table>
</body>
</html>

JQuery学习三(隐式迭代和节点遍历)的更多相关文章

  1. js的事件循环绑定和jQuery的隐式迭代

    js的事件循环绑定和jQuery的隐式迭代 js事件循环绑定 jQuery隐式迭代 先举一个例子:给定一个ul,点击列表内的每一个li元素,使它的背景色变红,下边分别用js代码和jQuery实现. & ...

  2. jQuery关于隐式迭代的个人理解~

    1.JQuery对象" 如: $('div').text("div展示的信息") 可以看成"是一个包含一个dom数组 和 包含所有Jquery方法的容器 2.每 ...

  3. JQuery的链式编程,隐式迭代是啥意思?

    链式编程 1.好处 "一句话,链式编程可以省去很多重复的代码." 这话什么意思呢?举个例子. /*设置obj对象的两个属性*/ //普通做法是这样的 obj.name = '小明' ...

  4. jQuery——链式编程与隐式迭代

    链式编程 1.原理:return this; 2.通常情况下,只有设置操作才能把链式编程延续下去.因为获取操作的时候,会返回获取到的相应的值,无法返回 this. 3.end():结束当前链最近的一次 ...

  5. JQuery的链式编程与隐式迭代

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. jquery 点谁谁哭-隐式迭代

    <!DOCTYPE html><html lang="en" xmlns="http://www.w3.org/1999/xhtml"> ...

  7. jQ的隐式迭代和设置样式属性

    jQ中的隐式迭代 意义:不需要原生迭代了,在jQ内部自动帮你实现了循环 代码实现: let arr = document.querySelectorAll('li') for(let i = 0;i ...

  8. jQ的显式迭代和隐式迭代

    jQ的显示迭代 隐式迭代 let lis = document.querySelector('li') lis.forEach(function (value, index) { value.styl ...

  9. JQuery的隐式迭代和each函数和map函数

    1.JQuery选择器选择出来的是一个数组对象,可是给这些每一个元素都要设置内容时,就会隐式迭代,JQuery自己实现内部循环给每个元素绑定上设置. 2.如果是获取的话,那就是默认获取第一个元素的值. ...

随机推荐

  1. 大理石在哪儿 (Where is the Marble?,UVa 10474)

    题目描述:算法竞赛入门经典例题5-1 #include <iostream> #include <algorithm> using namespace std; ; int m ...

  2. Appium ——Android KEYCODE键值:

    Python下语法: driver.keyevent(键值) 电话按键: 键名 描述 键值 KEYCODE_CALL 拨号键 5 KEYCODE_ENDCALL 挂机键 6 KEYCODE_HOME ...

  3. Map Reduce Application(Top 10 IDs base on their value)

    Top 10 IDs base on their value First , we need to set the reduce to 1. For each map task, it is not ...

  4. 利用人脸特征提取DeepID--解读世纪晟人脸识别

    概述:DeepID的目标是人脸验证(判断两张图片是否是一个人),同时衍生出人脸识别(多次人脸验证). DeepID采用增大数据集的方法: 增加新的数据,celebFaces(87628张图片,5436 ...

  5. js经典试题之常用的方法

    js经典试题之常用的方法 1.下面代码输出的值 let s = "bob" const replaced = s.replace('b', 'l') replaced === &q ...

  6. 搭建备份到业务迁移---mysql

    mysql安装启动以及配置 使用到阿里云主机直接yum安装以及配置 [root@yunwei-169 mysql]# yum install mysql mysql-server [root@yunw ...

  7. Train Problem(栈的应用)

    Description As the new term comes, the Ignatius Train Station is very busy nowadays. A lot of studen ...

  8. 欢迎来怼--第二十一次Scrum会议

    一.小组信息 队名:欢迎来怼 小组成员 队长:田继平 成员:李圆圆,葛美义,王伟东,姜珊,邵朔,冉华 小组照片 二.开会信息 时间:2017/11/2 17:05~17:15,总计10min. 地点: ...

  9. sigsuspend

    1)头文件:#include <signal.h> 2)一个保护临界区代码的错误实例:(sigprocmask()和pause()实现) #include <unistd.h> ...

  10. HDU 2133 What day is it

    http://acm.hdu.edu.cn/showproblem.php?pid=2133 Problem Description Today is Saturday, 17th Nov,2007. ...