Why doesn't a jQuery change function work after loading html with AJAX?

前端 未结 3 661
遥遥无期
遥遥无期 2020-12-10 13:06

I load a form and dynamically populate a select via AJAX from a PHP file. Before implementing the dynamic AJAX populated select, my change function works (it just shows anot

3条回答
  •  情书的邮戳
    2020-12-10 14:04

    I think the element you are binding to in the line:

    $('#ve_categoryNo').change(function() { ...
    

    does not yet exist in the DOM, so the event does not get bound.

    Try using the .live function:

    $('#ve_categoryNo').live('change', function() { ... });
    

    Or make sure that your DOM elements exist before you try to bind events to them.

提交回复
热议问题