上一篇讲到了页面页内的平滑移动.这里就要用到.这里要复习一下addClass和attr..根据前面讲到的内容.我们在此应用一下.addClass就不多说了.前面也举了例子.
关于attr(name).
取得第一个匹配元素的属性值.通过这个方法可以方便地从第一个匹配元素中获取一个属性的值.如果元素没有相应属性,则返回 undefined
Access a property on the first matched element. This method makes it easy to retrieve a property value from the first matched element. If the element does not have an attribute with such a name, undefined is returned.
为了帮助理解.实例一个:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | <html > <head> <title>test attr(name)</title> <script type="text/javascript" src="jquery-1.2.6.min.js"></script> <script language="javascript"> $().ready(function(){ var D=$("img").attr("src"); alert(D); }); </script> </head> <body> <img src="philna.jpg" alt="" /> </body> </html> |
通过实例.我们得到了src的值.
以这个inove主题为例.前面说到鼠标悬浮显示了留言内容的’教程’中实现了给特定的含有@和comment的字符链接添加class.代码是这样的:
1 2 3 4 5 6 | //match add class var A=/^#comment-/; var B=/^@/; if($('#thecomments .info .content p a').text().match(B) && $('#thecomments .info .content p a').attr('href').match(A)){ $('#thecomments .info .content p').addClass('cool'); }; |
因此配合前面的滑动js添加如下代码就可以实现了:
1 | $('.cool a').click(function(){$($(this).attr("href")).ScrollTo(设定时间-单位毫秒);return false;}); |
声明:本站遵循署名-非商业性使用-相同方式共享3.0共享协议. 转载请注明转自 PhilNa ™
十二点前 来道声节日快乐^^ 顺便后面那个“蛋”也捎带着祝福了!