Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用jquery或javascript在鼠标上显示和隐藏文本?_Javascript_Jquery - Fatal编程技术网

如何使用jquery或javascript在鼠标上显示和隐藏文本?

如何使用jquery或javascript在鼠标上显示和隐藏文本?,javascript,jquery,Javascript,Jquery,函数悬停(){ //在div id=dynamicDivFirstModule中显示某些内容 } 函数HoverClear(){ //清楚的// } 像这样试试 <div id="dynamicDivFirstModule" style="height:600; width:500; background-color:red;">something else</br> <span id="textSpan" style="display:none;">

函数悬停(){
//在div id=dynamicDivFirstModule中显示某些内容
} 
函数HoverClear(){
//清楚的//
}

像这样试试

<div id="dynamicDivFirstModule" style="height:600; width:500; background-color:red;">something else</br>
<span id="textSpan" style="display:none;">Text appears</span>
</div>




$(document).ready(function(){
    $("#dynamicDivFirstModule").on('mouseenter',function() {
        $("#textSpan").show();
    });
    $("#dynamicDivFirstModule").on('mouseout',function() {
        $("#textSpan").hide();
    });
});

正如您所说的,您希望文本显示在我开发的这段代码的鼠标指针上,这可能会对您有所帮助

html

js


一个简单的jQuery悬停函数可以:

$(document).ready(function(){
    $("#hoverHere").hover(
       function() 
       {
          $("#hover").show();
       },
       function() 
       {
          $("#hover").hide();
       }
    );
});

什么元素应该具有悬停效果?我是说,悬停哪个元素来显示div内容?@Syed有什么答案吗?
<div>A</div>
<div>B</div>
<span id="textSpan" style="display:none;position:absolute;"></span>
div{
  width: 10px;
  cursor :default;
}
$(document).ready(function(){
$("div").on('mouseover',function(e) {
    var div = $(this).html();
    $("#textSpan").html(div).css({left:e.pageX, top:e.pageY-15}).show();
});
    $("div").on('mouseout',function(e) {
     $("#textSpan").hide();
    });
});
$(document).ready(function(){
    $("#hoverHere").hover(
       function() 
       {
          $("#hover").show();
       },
       function() 
       {
          $("#hover").hide();
       }
    );
});