2011-07-22 83 views
0
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<title>Untitled Document</title> 
<script src="jquery-1.6.2.js"></script> 
<script> 
$("#test").live("click", function(){ 
    alert('');   
}); 
$("#tbl").live("mouseover",function(){ 
    $("#title").html('<input id="test" type="button" value="test button" />'); 
}); 
$("#tbl").live("mouseleave",function(){ 
    $("#title").html(''); 
}); 

</script> 

</head> 
<body> 
<table id='tbl' width="200" border="1"> 
    <tr> 
    <td id="title">&nbsp;</td> 
    </tr> 
    <tr> 
    <td id="content">&nbsp;</td> 
    </tr> 
</table> 
</body> 
</html> 

$(“#test”)。live(“click”...)不起作用,但如果我改变鼠标悬停它的作品。 任何人都可以提供帮助吗?jquery:鼠标悬停工作,但点击不会'工作

感谢, 程

回答

0

你的问题是,你使用的是mouseover而不是mouseenter。我有一个工作示例here

+0

不错!非常感谢! – cheng

+0

是的,每当你移动或点击导致按钮一遍又一遍地被替换的鼠标时,mouseover事件被触发。 –

0

程:

只是一个尝试,但尝试把 ';'在您的报表的两端:

$("#test").live("click", function(){ 
    alert(); 
}); 
$("#tbl").live("mouseover",function(){ 
    $("#title").html('<input id="test" type="button" value="test button" />'); 
}); 
$("#tbl").live("mouseleave",function(){ 
    $("#title").html(''); 
}); 
+0

不起作用。但感谢 – cheng

+1

用'alert('')替换'alert();'并且它可以工作 – Tomm

+0

在某些情况下(如单行函数),你不需要分号,这就是其中之一。 – Fred

0

问题alert()不喜欢这个工作。只是这样做alert('');

+0

同样的事情,它适用于mouseover事件,但不能点击 – cheng

0

你只需要在alert('Something')声明中放置一个字符串。

我有一个工作示例here (jsFiddle)

0

尝试更换警报()通知( “任何”); 这只是在我的电脑上正常工作。

1

使用mouseenter instessd mouseover,和@davecoulter说的那样“;”在statments结束,

$("#test").live("click", function(){ 
     alert(); 
    }); 
    $("#tbl").live("mouseenter",function(){ 
     $("#title").html('<input id="test" type="button" value="test button" />'); 
    }); 
    $("#tbl").live("mouseleave",function(){ 
     $("#title").html(''); 
    }); 

这里是的jsfiddle http://jsfiddle.net/Z2ZYs/1/

+0

并将'alert();'改为'alert('');'! – Fred

+0

没有它,它会跟我一起走,但它会说未开封 –