jQuery 学习笔记

来源:互联网 发布:易语言编程教学 编辑:程序博客网 时间:2024/06/05 04:22

jQuery 写法

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

解决不同库之间的冲突

//jQuery conflictjQuery.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>>

0 0