jquery笔记
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了jquery笔记,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含7088字,纯文字阅读大概需要11分钟。
内容图文
function one(){
var $question = $(".question");
$question.bind("click",function(){
var $nextele = $(this).next();//定义局部变量
if($nextele.is(":hidden")){//判断回答的元素是否可见
$nextele.show();
$question.html("good for you");
$question.css("color","red")
}else{
$nextele.hide();
$question.html("Do you konw about jquery");
$question.css("color","black")
}
})
$question.mouseover(function(){
$(this).next().show();
}).mouseout(function(){
$(this).next().hide();
})
// 合成事件 hover()
$question.hover(function(){
$(this).next().show();
},function(){
$(this).next().hide();
}
)
})
$("element").bind("click",function(even){//event:事件对象当你点击element元素的时候,点击事件就被创建了,这个事件对象只有事件处理函数才能访问的到,事件处理函数执行完毕后,事件对象就会被销毁。
})
$("element").bind("click",function(even){//event:事件对象这样在element元素的事件被触发的时候,就不会影响到其他元素的事件了。
event.stopPropagation()//停止事件冒泡
})
var $btn = $("#password");如果想同时对事件对象停止冒泡和默认行为,可以在事件处理函数中返回false,这是对在事件对象上同时调用stopprapagation()方法和preventDefault()方法的一种简写
$btn.bind("click",function(event){
var $user = $("#userName").val();//输入框对象
if($user==""){//判定它的值是不是为空
event.preventDefault();//阻止默认行为
}
})
var $btn = $("#password");
$btn.bind("click",function(event){
var $user = $("#userName").val();//输入框对象
if($user==""){//判定它的值是不是为空
return false;
}事件捕获:
})
$btn.bind("click",function(event){
console.info(event.type);
})2:event.preventDefault()方法
$btn.bind("click",function(event){
console.info(event.target);
})
// 多个元素绑定同一个事件:移除按钮元素上以前注册的事件:
$(".addbtn").bind("click",function(evetn){
$(".add-text").append("<b>我是一号</b>");
}).bind("click",function(event){
$(".add-text").append("<b>我是二号</b>");
}).bind("click",function(evetn){
$(".add-text").append("<b>我是三号</b>");
})
// 多个元素绑定同一个事件:
$(".addbtn").bind("click",fun1=function(evetn){
$(".add-text").append("<p>我是一号</p>");
}).bind("click",fun2=function(event){
$(".add-text").append("<p>我是二号</p>");
}).bind("click",fun3=function(evetn){
$(".add-text").append("<p>我是三号</p>");
})
$(".removebtn").bind("click",function(event){
$(".addbtn").unbind("click",fun2)//移除按钮的第二个事件
})
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml/DTD/xhtml1-Transitional.dtd">
// 基本逻辑:1创建jquery对象,给对象设置点击事件,当用户点击元素的时候,元素开始运动。按照顺序执行:
$(function(){
$ball = $(".one");
$ball.bind("click",function(event){
$(this).animate({left:"50em",width:"20em",height:"20em",color:"red"},3000);
return false;//阻止事件冒泡和默认行为
})
})
$(function(){
$ball = $(".one");
$ball.bind("click",function(event){
$(this).animate({left:"50em",width:"20em",height:"20em",color:"red"},3000)
.animate({top:"10em",opacity:"0.7"},3000)
.animate({left:"0",width:"10em",height:"10em"},3000)
.animate({top:"0",opacity:"1"},3000)
return false;//阻止事件冒泡和默认行为
})
})
综合动画:
$(function(){动画回调函数:
$ball = $(".one");
$ball.bind("click",function(event){
$(this).animate({left:"50em",width:"20em",height:"20em",color:"red"},3000)
.animate({top:"10em",opacity:"0.7"},3000)
.animate({left:"0",width:"10em",height:"10em"},3000)
.animate({top:"0",opacity:"1"},3000)
.fadeOut("slow");//0.6s
return false;//阻止事件冒泡和默认行为
})
})
$(function(){css本来是不会加入到动画队列的,一定会最先执行,但是你已经开始了动画效果,那么就需要你使用回调函数了,可以想象成一个指针,当动画结束的时候,立刻就能回调,
$ball = $(".one");
$ball.bind("click",function(event){
$(this).animate({left:"50em",width:"20em",height:"20em",color:"red"},3000)
.animate({top:"10em",opacity:"0.7"},3000)
.animate({left:"0",width:"10em",height:"10em"},3000)
.animate({top:"0",opacity:"1"},3000,function(){
$(this).css("border","5px solid black")
})
// .fadeOut("slow");//0.6s
return false;//阻止事件冒泡和默认行为
})
})
原文:http://www.cnblogs.com/gavinzzh-firstday/p/5444870.html
内容总结
以上是互联网集市为您收集整理的jquery笔记全部内容,希望文章能够帮你解决jquery笔记所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。