我希望當鼠標懸停在圖像上時,一個事件應該被觸發一次,並且只有在鼠標不在該圖像中並且再次返回時纔會觸發事件,並且至少還要經過2秒鐘。 我現在的功能不斷(refreshcash
)呼籲,如果我離開鼠標滑過我的形象JavaScript/jQuery onmouseover問題
<img src="images/reficon.png" onmouseover="refreshcash()" onmouseout="normalimg()" id="cashrefresh"/>
function refreshcash() {
$("#showname").load('./includes/do_name.inc.php');
$("#cashrefresh").attr("src","images/reficonani.gif");
}
function normalimg() {
$("#cashrefresh").attr("src","images/reficon.png");
}
代碼更新 此代碼似乎有一個bug,但是算法是有點邏輯
<script type="text/javascript">
var canhover = 1;
var timeok = 1;
function redotimeok() {
timeok = 1;
}
//
function onmenter()
{
if (canhover == 1 && timeok == 1)
{
enter();
canhover = 0;
}
}
//
function onmleave()
{
leave();
canhover = 1;
setTimeout(redotimeok(), 2000);
leave();
}
//
$('#cashrefresh').hover(onmenter(),onmleave());
function enter(){
$("#showname").load('./includes/do_name.inc.php');
$("#cashrefresh").attr("src","images/reficonani.gif");
}
function leave(){
$("#cashrefresh").attr("src","images/reficon.png");
}
</script>
@Sarfraz:只是好奇:你爲什麼改變5秒鐘2秒? – 2010-08-05 19:38:17
@Marcel Korpel:我沒有,只是用Cntr + K格式化了代碼,我不認爲這應該代替任何字符:) – Sarfraz 2010-08-05 19:40:08
@Sarfraz:Then [that](http://stackoverflow.com/posts/ 3418472/revisions#revee94a44e-d271-4f3d-a6ab-4702bc7db9b0)*非常*很奇怪......;) – 2010-08-05 19:55:31