'change' event, ajax and live() on IE7
I read a lot of posts about the problem I have, but haven't been able to fix it. I'm using jquery 1.5.1 and I have a problem with 'change' event on IE7. Since interoperability is a must, I've been trying (unsuccessfully ) to get live() with 'change' event to work on IE7.
Some people have suggested using livequery(), but for me, this is also not a solution.
开发者_C百科Is there a way to make options form loaded with ajax respond to 'change' event on IE7 and what would you suggest?
Btw, code works perfectly on IE8 and FF.
Thanks! Newman
if you r not rendering select list with ajax u better use $(selector).change in document.ready function live will not propagate change event of select list in IE so you have to attach event handler to the select list itself.
Edit i load select list using following code
$.ajax({
type:"post",
url:"/controls/selectlist",
dataType:"html",
success:function(data)
{
$("#result").append(data);//data will contain html of my select list with ID = mylist
$("#mylist").change(function(){
//put event handling code here
});
}
});
have you tried delegate instead of live?
It works fine for me , must be your code or browser...
See my example here http://jsfiddle.net/blowsie/82Adg/3/
$("select").live('change', function(){
alert('change')
});
$("#button").click(function(){
$("body").append("<select><option value='1'>1</option><option value='2'>2</option></select>")
return false
});
精彩评论