我正在使用此代码,但它不显示警报;jquery悬停不会显示警报
$(document).ready(function() {
$(".one").hover(
alert("hello");
});
});
我在做什么错?
我正在使用此代码,但它不显示警报;jquery悬停不会显示警报
$(document).ready(function() {
$(".one").hover(
alert("hello");
});
});
我在做什么错?
你错过了一个函数声明。 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");
}
你也可以使用mouseover
和mouseout
事件以及:
$(".one").on({
"mouseover" : inWeGo,
"mouseout" : outWeCome
});
hover
是这两种方法的简写。在文档
更多信息:
hover()
:http://api.jquery.com/hover/mouseover()
:http://api.jquery.com/mouseover/mouseout()
:http://api.jquery.com/mouseout/是`.one`动态创建@ user2309648ü可以弥补这方面小提琴@ jsfiddle.net – krishgopinath
似乎在这里工作:http://jsfiddle.net/E8geJ/ @ user2309648 – krishgopinath
$(".one").hover(function() {
alert("hello");
});
? 。 – krishgopinath