首页 > 通过jquery加载的元素,要怎样才能进行控制?

通过jquery加载的元素,要怎样才能进行控制?

原html

<body>
</body>

a.php

<?php
echo "<input id=\"cancel\" type=\"button\" value=\"取消\">";

jquery

$(document).ready(function(){
    $(".button").bind({
        click:function(){
            $.get("./create.php",function(data){
                $("body").append(data)
            })
        }
    })
    
    $("input").click(function(){
        alert(123456);
    })
})

新html

<body>
    <div>
        <input id="cancel" type="button" value="取消">
    </div>
</body>

题主的问题本质地是如何控制动态插入的新节点。用 jQuery 的话,可以这么来:

$(document).on('click', 'input', function() {
    alert(123456);
});
【热门文章】
【热门文章】