繁体   English   中英

如何将单击更改为鼠标悬停或通过jQuery悬停?

[英]how to change click to mouseover or hover through jquery?

我想在鼠标悬停或悬停时显示日期,现在是onclick,我已经使用工具提示来显示数据,但是我想在鼠标悬停时显示数据,我尝试了很多但是没有成功? 任何机构都可以提供帮助,在此先感谢您。

这是我的代码,它希望将clik更改为mouseiver / hover。

 <script>
 $(".ajax_link").click(function(e) {

e.preventDefault(); //Stops link from changing the page

var link = $(this).attr('href'); //Gets link url

$.ajax({ //Make the ajax request
  url: link,
  cache: false
}).done(function( html ) { //On complete run tooltip code

    //Display tooltip code goes here, returned text is variable html
    .done(function( html ) { 
        alert("text: " + html);
    });
});
});
</script>

您可以尝试更改此设置:

$(".ajax_link").click(function(e) {

对此:

$(document).on('hover mouseover mouseenter', ".ajax_link", function(e) {
     //e.preventDefault(); //<-------you can take this out no need for this

如果要停止页面跳转,可以执行以下操作:

$(".ajax_link").click(function(e) {
   e.preventDefault(); // or return false;
});

您可以使用它。它对两个事件都适用。

 $('#element').on('hover mouseover', function() {
        ...
    });

为什么不只是:

 <script>
$(".ajax_link").mouseover(function(e) {

e.preventDefault(); //Stops link from changing the page

var link = $(this).attr('href'); //Gets link url

$.ajax({ //Make the ajax request
  url: link,
  cache: false
 }).done(function( html ) { //On complete run tooltip code

//Display tooltip code goes here, returned text is variable html
.done(function( html ) { 
    alert("text: " + html);
});
});
});
</script>

有某些原因不能使用.mouseover吗?

使用悬停功能。

$('id').hover(function() {
  /* code for mouseover */
}, function() {
 /* code for mouseout */
});

暂无
暂无

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

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