jQuery with elements generated dynamically

前端 未结 6 1567
旧巷少年郎
旧巷少年郎 2021-01-19 16:14

I\'ve been working with jQuery for a pair of weeks and I\'ve noticed it works fine with objects that are in the original HTML document, but when I generate a new element usi

6条回答
  •  终归单人心
    2021-01-19 16:53

    You need to rebind it.

    function bindme(){
        $('.whatever').click(function(){
            alert('binded');
        });
    };
    
    bindme();
    
    //function that will generate something
    
    function foo(){
       $('.whatever').val('oryt');
       bindme();//rebind itagain
    }
    

提交回复
热议问题