分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 前端开发

jQuery_事件学习

发布时间:2023-09-06 01:23责任编辑:彭小芳关键词:jQuery

一、click事件

click事件----鼠标单击事件

$(‘.bt‘).click(function() { alert("本身的事件");})

当class为bt的div被但单击时执行函数体的内容部分

 $(‘.bt‘).click(function() { ?????????$(‘.bt2‘).click(); ???????})
当class为bt的div被但单击时执行class为bt2的div的click()事件

栗子:
<!DOCTYPE html><html><head> ???<meta http-equiv="Content-type" content="text/html; charset=utf-8" /> ???<title></title> ???<style> ??.bt{ ??????background:#F00; ?????????} ??.bt2{ ??????background:#f0f; ??????display:none; ??} ???</style> ???<script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script></head><body> ???<div class="bt">click()鼠标单击事件</div> ????<div class="bt2">间接响应</div> ???<script type="text/javascript"> ???????$(‘.bt‘).click(function() { ???????????alert("本身的事件"); ?????????$(‘.bt2‘).click(); ???????}) ????????$(‘.bt2‘).click(function() { ?????????alert("调用其他对象绑定的事件"); ???????})</script></body></html>

二、mousemove()和mousemout()

鼠标移入(当鼠标移入到该元素的内部时触发)和移出事件(当鼠标移出元素的内部时触发)

栗子:

<!DOCTYPE html><html><head> ???<meta http-equiv="Content-type" content="text/html; charset=utf-8" /> ???<title></title> ???<style> ???</style> ???<script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script></head><style> ???.test{ ???????height:100px; ???????width:100px; ???????background:#F00; ???} ???</style><body> ???<h2>.mousemove()方法</h2> ???<div class="test"></div> ???<script type="text/javascript"> ????//鼠标移入事件 ???$(".test").mousemove(function(){ ????????$(".test").css({"background":"blue","width":"100px","height":"100px"}); ???}); ???//鼠标移出事件 ????$(".test").mouseout(function(){ ????????$(".test").css({"background":"yellow","width":"50px","height":"50px"}); ????}); ???</script></body></html>

三、hover事件

hover()方法是同时绑定 mouseenter和 mouseleave事件。

使用:hover(function(){

  鼠标移入元素时触发的内容

  },function(){

  鼠标移出元素时触发的内容

})

栗子:

<!DOCTYPE html><html><head> ???<meta http-equiv="Content-type" content="text/html; charset=utf-8" /> ???<title></title> ???<style> ???.test{ ???????width:100px; ???????height:100px; ???????background:#000; ???????color:#FFF; ???} ???????</style> ???<script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script></head><body> ???<div class="test">hover()事件</div> ???<script type="text/javascript"> ???$(".test").hover(function(){ ???????$(".test").css("background","red"); ???},function(){ ???????$(".test").css("background","blue"); ???}); ???</script></body></html>

四、focusin()聚焦事件和focusout()失焦事件

聚焦事件--当该元素获得聚焦时触发

失焦事件---当该元素失去焦点时触发

栗子:

<!DOCTYPE html><html><head> ???<meta http-equiv="Content-type" content="text/html; charset=utf-8" /> ???<title></title> ???<script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script></head> <body> ???<p>聚焦事件:<input class="in"/></p> ???<p>失焦事件:<input class="ot"/></p> ???<script type="text/javascript"> ???????//input聚焦元素增加一个边框 ???????$(".in").focusin(function() { ????????????$(this).css(‘border‘,‘2px solid red‘); ???????}); ???????$(".ot").focusout(function(){ ???????????alert("真的要放弃填写吗?"); ???????}); ???</script></body></html>

jQuery_事件学习

原文地址:http://www.cnblogs.com/soulsjie/p/7811087.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved