最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

Jquery中关于blur和focus事件无法生效的解决办法

来源:动视网 责编:小采 时间:2020-11-27 20:18:34
文档

Jquery中关于blur和focus事件无法生效的解决办法

Jquery中关于blur和focus事件无法生效的解决办法:Jquery blur和focus事件无法生效$(function(){ alert("页面生效"); $(".login_shopcart").blur(function(){ alert("blur生效"); $(".shopcart_img").attr(&qu
推荐度:
导读Jquery中关于blur和focus事件无法生效的解决办法:Jquery blur和focus事件无法生效$(function(){ alert("页面生效"); $(".login_shopcart").blur(function(){ alert("blur生效"); $(".shopcart_img").attr(&qu


Jquery blur和focus事件无法生效

$(function(){
 alert("页面生效");
 $(".login_shopcart").blur(function(){
 alert("blur生效");
 $(".shopcart_img").attr("src","myimg/shopcart_img.png");
 $("#ShopCart_num").show();
 });
 $(".login_shopcart").focus(function(){
 alert("focus生效");
 $(".shopcart_img").attr("src","myimg/Login.png");
 $("#ShopCart_num").hide();
 });
});

代码如上:第一个页面alert()能够生效,但是blur和focus无法生效。我用的是Jquery1.9.1版本。
求大神指点

页面HTML呢? 得触发 .login_shopcart 这个元素才行

这段代码是写在引入的JS文件里面

你把HTML也发出来呀。不然咋知道是你JS的问题还是你HTML的问题
说不定你页面压根就没 class="login_shopcart" 的 对象

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
$(function(){
 alert("页面生效");
 $(".login_shopcart").blur(function(){
 alert("blur生效");
 $(".shopcart_img").attr("src","myimg/shopcart_img.png");
 $("#ShopCart_num").show();
 });
 $(".login_shopcart").focus(function(){
 alert("focus生效");
 $(".shopcart_img").attr("src","myimg/Login.png");
 $("#ShopCart_num").hide();
 });
 $(document).ready(function(){
 alert("document生效");
 $(".login_shopcart").ready(function(){
 });
 });
});
</script>
</head>
<body>
 <div class="login_shopcart" style="position:fixed;bottom:0px;right:100px;">
 <p style="position: absolute;padding: 10px 0 0 40px;color:white;" id="ShopCart_num">0</p>
 <img alt="#" src="myimg/ShopCart.png" class="shopcart_img">
 </div>
</body>
</html>

而且div元素没有blur和focus事件

Jquery导入也没法运行

拜托,,div的话,用

$(function () {
 alert("页面生效");
 $(".login_shopcart").hover(function () {
 alert("blur生效");
 $(".shopcart_img").attr("src", "myimg/shopcart_img.png");
 $("#ShopCart_num").show();
 }, function () {
 alert("focus生效");
 $(".shopcart_img").attr("src", "myimg/Login.png");
 $("#ShopCart_num").hide();
 
 });
 });


不知道你是要鼠标悬浮还是鼠标点击
思路:获取焦点 login_shopcart 直接绑定click
失去焦点 document绑定click,让login_shopcart点击无效
部分代码例子:

$(document).click(function(){
 $("#login_shopcart").click(function(){
 return false;
 });
 $(".shopcart_img").attr("src","myimg/shopcart_img.png");
 $("#ShopCart_num").show();
 });

感谢各位大神~~~找到原因了。DIV确实无法使用blur和focus~~~改成mouseover 和mouseout生效了~~

文档

Jquery中关于blur和focus事件无法生效的解决办法

Jquery中关于blur和focus事件无法生效的解决办法:Jquery blur和focus事件无法生效$(function(){ alert("页面生效"); $(".login_shopcart").blur(function(){ alert("blur生效"); $(".shopcart_img").attr(&qu
推荐度:
标签: 事件 jQuery blur
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top