我有一个jquery函数,可以在所有浏览器中运行,但不能在兼容模式下的ie7和ie9中运行。 问题出在这个函数上:
$('.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);
});
错误是:
SCRIPT87: Invalid argument.
jquery.min.js, line 4 character 23894
如何修复它?
最佳答案
很可能是您确定 margin_slider
的方式导致了该问题。它必须在 parseInt
中返回 NaN
。
在 .animate
之前尝试 alert(margin_slider)
并查看它返回的内容。
这还取决于您要迭代的内容。调试更多内容以查看 n_btn
返回的内容以及预期的内容。如果n_btn
返回一个数字字符串或任何以数字开头的字符串应该返回you are number..但似乎没有。
尝试使用 .charAt(i)
代替 $(this).attr('id')[i]
。您可以 var thisId = this.id
然后使用 var 而不是 $(this).attr('id')
关于jquery - 脚本87 : Invalid argument,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10390252/