JQuery event handler when select element is loaded

前端 未结 7 1786
清歌不尽
清歌不尽 2021-01-03 01:53

Is there an event handler to use in JQuery when a DOM select element has finished loading? This is what I want to achieve. It is working with other events e

7条回答
  •  太阳男子
    2021-01-03 02:48

    Ok, correct me if I understand this wrong. So you want to do something with the selects when the document is loaded and also after you get some fresh data via an ajax call. Here is how you could accomplish this.

    First do it when the document loads, so,

    
    

    Now everytime you have an ajax request the ajaxSend and ajaxComplete functions are called. So, add this after the above:

    $(document).ajaxSend(function () {
    }).ajaxComplete(function () {
        alterSelects();
    });
    

    The above code will fire as soon as the request is complete. But I think you probably want to do it after you do something with the results you get back from the ajax call. You'll have to do it in your $.post like this:

    $.post("yourLink", "parameters to send", function(result){
        // Do your stuff here
        alterSelects();
    });
    

提交回复
热议问题