问题
I have a jquery function that works in all browser, but not in ie7 and ie9 in compatibily mode. The problem is in this function:
$('.non-attivo').live('click',function(){
clearInterval(start_slide);
n_btn = "";
for(var i=1;i<$(this).attr('id').length; i++)
n_btn += $(this).attr('id')[i] + "";
slide_pos = parseInt(n_btn, 10);
var margin_slider = slide_pos * 780;
$('#immagini').animate({ marginLeft: "-" + margin_slider + "px"}, 500 );
$('.attivo').attr('class', 'non-attivo');
$(this).attr('class', 'attivo');
start_slide = setInterval(rotate, 4000);
});
The error is:
SCRIPT87: Invalid argument.
jquery.min.js, line 4 character 23894
How can I fix it?
回答1:
Mostlikely the way you determine margin_slider is causing the issue. It must be returning a NaN in parseInt.
Try alert(margin_slider) before .animate and see what it returns.
Also It depends on what you are iterating.. Debug more to see what is getting returned for n_btn and what is expected. If n_btn returns a numeric string or any string beginning with number should return you are number.. but seems like it doesn't.
Try using .charAt(i) instead $(this).attr('id')[i]. And you can var thisId = this.id and then use the var instead of $(this).attr('id')
回答2:
I ran into this problem a few days ago.
In case anyone else also stumbles upon this, the issue was that I was using HTML button elements which IE9- doesn't seem to know how to handle. Adding a HTML shim solved the problem.
来源:https://stackoverflow.com/questions/10390252/script87-invalid-argument