2013-07-06 107 views

回答

4

你错过了一个函数声明。 hover接受一个函数(或两个函数)作为参数。你的代码改成这样:

$(".one").hover(function() { 
    alert("hello"); 
}, function() { 
    alert("And we're out"); 
}); 

第一个功能是为这是当你将鼠标悬停在.one发生的动作。第二个是你徘徊在.one之外。你也可以这样来做:

$(".one").hover(inWeGo, outWeCome); 

function inWeGo() { 
    alert("hello"); 
} 

function outWeCome() { 
    alert("And we're out"); 
} 

你也可以使用mouseovermouseout事件以及:

$(".one").on({ 
    "mouseover" : inWeGo, 
    "mouseout" : outWeCome 
}); 

hover是这两种方法的简写。在文档

更多信息:

+0

@ hungerpain: Home <脚本类型= “文本/ JavaScript的”> $( “一个 ”)悬停(函数(){ 警报(“ 你好”); }); ? 它不工作 – IceDawg

+0

@ user2309648ü可以弥补这方面小提琴@ jsfiddle.net – krishgopinath

+1

似乎在这里工作:http://jsfiddle.net/E8geJ/ @ user2309648 – krishgopinath

5
$(".one").hover(function() { 
    alert("hello"); 
});