您的位置:首页 > Web前端 > JQuery

jQuery 学习笔记

2015-07-29 19:30 686 查看
jQuery 写法

//standard version
$(document).ready(function(){
alert("jQuery hello World");
});

//short version
$(function(){
alert("jQuery hello World");
});


解决不同库之间的冲突

//jQuery conflict
jQuery.noConflict();
(function($) {
$(function() {
// 使用 $ 作为 jQuery 别名的代码
});
})(jQuery);
// 其他用 $ 作为别名的库的代码


is() 方法

$(function(){
$(".head").click(function(){
var flag=$(".content").is(":hidden");
if(flag){
$(".content").show();
}else{
$(".content").hide();
}
});
})


bind() 方法

$(function(){
$(".head").bind("click",function(){
var flag=$(".content").is(":hidden");
if(flag){
$(".content").show();
}else{
$(".content").hide();
}
});
})


toggle()

$(".head").toggle(function(){//click
$(".content").show();
}, function(){
$(".content").hide();
});


hover()

$(".head").hover(function(){
$(".content").show();//mouseover
}, function(){
$(".content").hide();//mouseout
});


fadeTo()

$(function(){
$(".content").show();
var i=1;
$(".head").click(function(){
$(".content").fadeTo("slow",i);
i=i-0.1;
});
})


<<锋利的jQuery>>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: