脚本宝典收集整理的这篇文章主要介绍了javascript代码实例教程-ѧϰJQuery - 5,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。小宝典致力于为广大程序猿(媛)提供高品质的代码服务,请大家多多光顾小站,小宝典在此谢过。
在第2节中我们使用属性选择器实现了图标添加的工作,
那么我们能否使用遍历的方式来进行此类操作呢?答案是能。
在选择器之后增加一个遍历方法如:“filter”
$('tr').filter(':odd').addClass('alt');在遍历中我们可以进行一些处理,例如,可以在chapter02-1.htML的链接处增加一个图标
css代码
a.external { background: #fff url(images/external.png) no-rePEat 100% 2px; padding-right: 16px; }js代码
$('a').filter(function() { return this.hostname && this.hostname != location.hostname; }).addClass('external');
As You Like IT | Comedy | |
All's Well that Ends Well | Comedy | 1601 |
Hamlet | Tragedy | 1604 |
Macbeth | Tragedy | 1606 |
romeo and Juliet | Tragedy | 1595 |
Henry IV, Part I | History | 1596 |
Henry V | History | 1599 |
The Fair Youth | 1-126 |
The Dark Lady | 127-152 |
The Rival Poet | 78-86 |
$('td:contains(Henry)').nextAll().addClass('highlight');
As You Like It | Comedy | |
All's Well that Ends Well | Comedy | 1601 |
Hamlet | Tragedy | 1604 |
Macbeth | Tragedy | 1606 |
Romeo and Juliet | Tragedy | 1595 |
Henry IV, Part I | History | 1596 |
Henry V | History | 1599 |
The Fair Youth | 1-126 |
The Dark Lady | 127-152 |
The Rival Poet | 78-86 |
整列高亮的时候,我们需要点DOM树形知识了!
TH和TD的父节点是TR
那么我们就要用到两个方法:parent(), children()
首先,我们定位TD;然后,查找她的父节点(TR);最后,再查找此列(TD+);
js代码
$('td:contains(Henry)').parent().children().addClass('highlight');实现效果
As You Like It | Comedy | |
All's Well that Ends Well | Comedy | 1601 |
Hamlet | Tragedy | 1604 |
Macbeth | Tragedy | 1606 |
Romeo and Juliet | Tragedy | 1595 |
Henry IV, Part I | History | 1596 |
Henry V | History | 1599 |
The Fair Youth | 1-126 |
The Dark Lady | 127-152 |
The Rival Poet | 78-86 |
觉得可用,就经常来吧! 脚本宝典 欢迎评论哦! js脚本,巧夺天工,精雕玉琢。小宝典献丑了!
以上是脚本宝典为你收集整理的javascript代码实例教程-ѧϰJQuery - 5全部内容,希望文章能够帮你解决javascript代码实例教程-ѧϰJQuery - 5所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。