jquery - 脚本87 : Invalid argument

标签 jquery jquery-animate

我有一个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/

相关文章:

javascript - 从 JSON 检索数据时 HTML 图像未正确对齐

jquery - 同位素 : How to display and set opacity values for unmatched items

javascript - jQuery 冒号选择器

javascript - jQuery 中的 .animate() 和 if 条件似乎不起作用

jQuery Dialog - 动画对话框从中心移动到右上角

javascript - jquery 专注于div应用CSS样式

javascript - 将 id 分配给单个列中存在的两个元素

jQuery Animation 立即启动而不缓动

jQuery 忽略 .fadeOut 上的元素内联 block

jquery - 使用 jQuery 的滑动和旋转页面网站