开发者

jquery: mouseover works, but click wont' work

开发者 https://www.devze.com 2023-03-22 07:38 出处:网络
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"> <html xmlns=\"http://www.w3.org/1999/xhtml\">
"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"...) 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消