jquery用法小结

JQuery

 

文档就绪函数

 

所有jquery函数位于一个document ready函数中

$(document).ready(function(){

---jquery functions---        

})

 

 

jQuery 语法

 

基础语法是:$(selector).action()

•美元符号定义 jQuery

•选择符(selector)“查询”和“查找” HTML 元素

jQuery action() 执行对元素的操作

:$(this).hide();  隐藏当前的 HTML 元素

 

 

jQuery 选择器

 

元素选择:

$(this) 选取当前 HTML 元素

$("p")  选取所有 <p> 元素

$("#test") 选取id="test" 的元素

$(".test") 选取所有 class="test" 的元素

$("p.test") 选取所有 class="test" <p> 元素

$("p#test") 选取 id="test" 的第一个 <p> 元素

$(this).parent()  获取当前的父级元素

$(this).next()    获取当前的后一元素

$(this).prev()    获取当前的前一元素

$(this).find(".test")  查找当前的所有 class="test" 的子元素

 

 

jQuery 效果

 

$(selector).hide() 隐藏被选元素

$(selector).show() 显示被选元素

$(selector).hide(speed,callback)

speed可为:"slow", "fast", "normal" 或毫秒

callback 参数是在 hide show 函数完成之后被执行的函数名称

 

切换:同hide show 函数有相同参数

$(selector).toggle() 切换(在隐藏与显示之间)被选元素

jQuery toggle() 函数使用 show() hide() 函数来切换 HTML

素的可见状态

 

滑动函数:同hide show 函数有相同参数

$(selector).slideDown() 向下滑动(显示)被选元素

$(selector).slideUp() 向上滑动(隐藏)被选元素

$(selector).slideToggle() 对被选元素切换向上滑动和向下滑动

 

Fade 函数:

$(selector).fadeIn() 淡入被选元素(同hide show 函数有相

同参数)

$(selector).fadeOut() 淡出被选元素(同hide show 函数有相

同参数)

$(selector).fadeTo() 把被选元素淡出为给定的不透明度(参数为:

speed,opacity,callbackopacity 参数规定减弱到给定的不透明度

)

例:$("button").click(function(){

    $("div").fadeTo("slow",0.25);

    });

 

自定义动画

 

$(selector).animate() 对被选元素执行自定义动画

1

<html>

<head>

<script type="text/javascript"

src="/jquery/jquery.js"></script>

<script type="text/javascript">

$(document).ready(function(){

  $("#start").click(function(){

  $("#box").animate({height:300},"slow");

  $("#box").animate({width:300},"slow");

  $("#box").animate({height:100},"slow");

  $("#box").animate({width:100},"slow");

  });

});

</script>

</head>

 

<body>

 

<p><a href="#" id="start">Start Animation</a></p>

 

<div id="box"

style="background:#98bf21;height:100px;width:100px;position:

relative">

</div>

 

</body>

</html>

2

<html>

<head>

<script type="text/javascript"

src="/jquery/jquery.js"></script>

<script type="text/javascript">

$(document).ready(function(){

  $("#start").click(function(){

  $("#box").animate({left:"100px"},"slow");

  $("#box").animate({fontSize:"3em"},"slow");

  });

});

</script>

</head>

 

<body>

 

<p><a href="#" id="start">Start Animation</a></p>

 

<div id="box"

style="background:#98bf21;height:100px;width:200px;position:

relative">

HELLO

</div>

 

</body>

</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值