我在这里有一些代码,当你将鼠标放在另一个元素上时,它应该在1个元素上改变display: none
到display: block
。如何使用jQuery显示HTML元素?
HTML:
<li onmouseover="popup('Ipsum');">Lorem</li>
的Javascript:
$(document).ready(function(){
$("body").append('<div id="pup"></div>'); // Appends a popup div to the page
$(document).mousemove(function(e){
var x,y; // This sets the mouse
// coordinates into 2
x = $(document).scrollLeft() + e.clientX; // variables in order to
y = $(document).scrollTop() + e.clientY; // display the tooltip
}); // relative to mouse postition
function popup(text)
{
$('#pup').html(text); // This is supposed to enter text into the tooltip
$('#pup').show(); // div and change it from display: none to
// display: block
}
目前,DIV存在(但你看不到它,因为它是在CSS设置为display: none
,但是当你将鼠标悬停在li上时,它不显示。谢谢!
看一看移动弹出函数的定义中的$(document)。就绪之外(... )代码块。它应该在全球范围内定义。 – 2012-07-30 00:25:55
另一种方法是:只要执行'