如何改变点击鼠标悬停或通过jQuery的徘徊?(how to change click to mou

2019-08-17 09:41发布

我想显示在鼠标悬停日期或悬停,现在它的onclick,我已经使用工具提示中显示的数据,但我想显示在鼠标悬停的数据,我想了很多,但没有获得成功呢? 任何机构可以帮助它可以理解的,在此先感谢。

这是我的代码,它想改变CLIK到mouseiver /悬停。

 <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>

Answer 1:

你可以尝试改变这一点:

$(".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;
});


Answer 2:

您可以使用this.It将两个事件的工作。

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


Answer 3:

为什么不干脆:

 <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?



Answer 4:

使用悬停功能。

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


文章来源: how to change click to mouseover or hover through jquery?