📌  相关文章
📜  单击文档不起作用 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:47.058000             🧑  作者: Mango

代码示例1
$(document).ready(function() {
    // This WILL work because we are listening on the 'document', 
    // for a click on an element with an ID of #test-element
    $(document).on("click","#test-element",function() {
        alert("click bound to document listening for #test-element");
    });

    // This will NOT work because there is no '#test-element' ... yet
    $("#test-element").on("click",function() {
        alert("click bound directly to #test-element");
    });

    // Create the dynamic element '#test-element'
    $('body').append('
Click mee
'); });