简体   繁体   中英

jQuery: live change event on IE7

I have capture change event on drop down select. This drop down field is created using AJAX so event capture need to be done with live or bind. Here I add the code which I'm using currently. This is working on fire fox. On IE7 its not working. Can anyone tell me a way to capture live event of drop down select on IE7

<select id="lob_drop" name="opt" class="select">
       <option value="1">option 1</option>
       <option value="2">option 2</option>
       <option value="3">option 3</option>
    </select>

    jQuery('#lob_drop').live('change',function(){
       alert(jQuery('#lob_drop option:selected').val());
    });

Use jquery .on() . .live() is deprecated .

jQuery(document).on('change', '#lob_drop', function(){
       alert(jQuery('#lob_drop option:selected').val());
   }
);

Demo

What is your JQuery version ?

It works for me on IE7 using JQuery 1.4+ It seems live() wouldn't work with change event in IE in all previous versions.

Use the following:

$('body').on('change', '#lob_drop', function(){
   alert($(this).val());
});

Here's a fiddle with an example: http://jsfiddle.net/7EcGE/24/

My previous suggestion below won't work since .live is deprecated an removed since jQuery 1.9:

jQuery('#lob_drop').live('change',function(){
   alert(jQuery(this).val());
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM