清风的blog 优然探索

常用的jquery小技巧

$(document).ready(function() {


$("#orderedlist > li:last").addClass("blue");//first last取得第一个或者最后一个元素
$("li").css("background","red").css("color","gray");//一次设定两个css属性
$("a[@name]").background("#eee");//选择所有的带有name属性的链接
$("li[@name*='tu']").css("background","red");//部分匹配("*=")的方式来代替完全匹配("=")
$("li").not("[ul]").css("background", "red");//选择所有的没有ul子元素的li元素
$("a").hover(function() {$(this).parent("p").css("background","yellow");});//选择父级的元素

$("a").addClass("test").show().html("foo");//方法允许链接使用

$("p").filter([".selected", ":first"]);保留类名是selected的段落元素,同时保留第一个

 

$("a").hover(function() {
 $(this).parents("p").addClass("highlight");
}, function() {
 $(this).parents("p").removeClass("highlight");
});//移到文章某段的链接时,它所在的段全用上highlight样式,移走之后又恢复原样

 

 $("a")
   .filter(".clickme")
     .click(function(){
       alert("You are now leaving the site.");
     })
   .end()
   .filter(".hideme")
     .click(function(){
       $(this).hide();
       return false;
     })
   .end();//通过end()返回破坏性操作前调用的对象

 

});

 

2010年2月19日 | 发布:admin | 分类:学习收藏 | 评论:0

发表留言: