简体   繁体   English

Jquery 显示/隐藏悬停或鼠标输入问题

[英]Jquery show/hide hover or mouse enter issue

Ok so im trying to get some text that is hidden to display when the mouse enters the div then hide when it leaves好的,所以我试图让一些隐藏的文本在鼠标进入 div 时显示,然后在它离开时隐藏

so far ive got this on my fiddle到目前为止,我在我的小提琴上得到了这个

$(document).ready(function() {   
  $(".image").mouseover(function(){
 $(".hover").show();
 })
$(".image").mouseout(function(){
 $(".hover").hide();
});

Thanks any help would be great谢谢任何帮助都会很棒

You Should Read Basic of JavaScript你应该阅读JavaScript 基础

$(document).ready(function() {   
  $(".image").mouseover(function(){
  $(".hover").show();
  })
    $(".image").mouseout(function(){
  $(".hover").hide();
});
})//added

Updated Demo更新演示

You were missing a });你错过了一个});

Also, you can simplify your code to:此外,您可以将代码简化为:

$(document).ready(function () {
    $(".image").mouseover(function () {
        $(".hover").show();
    }).mouseout(function () {
        $(".hover").hide();
    });
});

BTW, your HTML is broken.顺便说一句,您的 HTML 已损坏。 Fix that first.先解决这个问题。

Both your HTML and JS code are badly written.你的 HTML 和 JS 代码都写得很糟糕。 And you didn't include jQuery is your jsfiddle, which means that '$' isn't recognized.而且您没有包含 jQuery 是您的 jsfiddle,这意味着无法识别 '$'。

$(document).ready(function() {
  $(".image").mouseover(function(){
      $(".hover").show();
  });
  $(".image").mouseout(function(){
      $(".hover").hide();
  });
});

You can test it here: http://jsfiddle.net/5PR5E/3/你可以在这里测试: http : //jsfiddle.net/5PR5E/3/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM