相关疑难解决方法(0)

Click事件不适用于动态生成的元素

<html>
<head>
    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript">

        $(document).ready(function() {

            $("button").click(function() {
                $("h2").html("<p class='test'>click me</p>")
            });   

            $(".test").click(function(){
                alert();
            });
        });

    </script>
</head>
<body>
    <h2></h2>
    <button>generate new element</button>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

我试图生成类名称的新标签test<h2>单击按钮.我还定义了一个与之关联的点击事件test.但事件不起作用.

有人可以帮忙吗?

jquery events

458
推荐指数
10
解决办法
49万
查看次数

jQuery是否有.delegate('hover')的句柄?

我正在尝试使用:

$('mydiv').delegate('hover', function() {  
    $('seconddiv').show();  
}, function() {  
    //For some reason jQuery won't run this line of code  
    $('seconddiv').hide();  
});
Run Code Online (Sandbox Code Playgroud)

jquery delegates handler

35
推荐指数
2
解决办法
2万
查看次数

标签 统计

jquery ×2

delegates ×1

events ×1

handler ×1