2013-03-08 130 views
1

我想在鼠标悬停或悬停上显示日期,现在它是onclick,我已经使用工具提示来显示数据,但我想在鼠标悬停上显示数据,我尝试了很多但没有成功?任何机构都可以提供帮助,敬请期待。如何更改点击鼠标悬停或通过jquery悬停?

这是我的代码,它想克隆到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> 
+0

有没有理由不能只使用.mouseover()? – Bernie 2013-03-08 05:40:08

+0

只是改变.click到.hover – dakait 2013-03-08 05:41:30

+0

你有没有尝试过使用'mouseenter()''mouseleave()'? – sweetamylase 2013-03-08 05:45:44

回答

1

为什么不干脆:

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

1

使用hover函数。

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

您试图编辑我的答案,因为它是多余的? http://stackoverflow.com/questions/15503535/how-can-i-select-one-object-per-each-related-object-in-django/15505469#15505469。如果你的编辑被批准了,那将会返回一个没有值的对象。编辑前请先尝试一下 – catherine 2013-03-20 02:03:14

2

你可以使用this.It将适用于这两个事件。

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

你可以尝试改变这个:

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