"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"> </td>
</tr>
<tr>
<td id="content"> </td>
</tr>
</table>
</body>
</html>
$("#test").live("click"...) doesn't work, but if I change to mouseover it works. Any on开发者_C百科e can help?
Thanks, Cheng
Use mouseenter
instessd of mouseover
,and as @davecoulter said put ";" end of the 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('');
});
here is the jsfiddle http://jsfiddle.net/Z2ZYs/1/
Your problem is that you are using mouseover instead of mouseenter. I have a working example here.
Cheng:
Just a stab, but try putting ';' at the ends of your statements:
$("#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('');
});
the problem is alert()
does not work like this . just do this alert('');
You just need to put a string in the alert('Something')
statement.
I have a working example here (jsFiddle)
Try replace alert() to alert("Anything"); It's just work fine on my computer.
精彩评论