2012-01-12 92 views
2

我在插入符(http://code.google.com/p/jquery-at-caret/)上使用jquery插件实现了非常大的脚本逻辑,但现在当我完成时我意识到它只适用于Firefox和Chrome,它在Internet Explorer中不起作用。插入插件的jquery在IE中不起作用

我意识到函数“setCaretPosition”是在IE中不起作用的函数。

我只接受IE“o未定义”,你可以在下面的代码片段中看到,这个 发生在79-89行的插件代码中,但我无法弄清楚如何解决这个问题。

创建非常小的代码片段只是复制此错误: http://www.mediafire.com/?xxt0medyci61690

+0

您正面临哪个版本的IE问题? – 2012-01-12 07:09:22

回答

3

我已经在插件

setCaretPosition: function(pos) { 
    var f1, f2, o; 
    o = this[0]; 
    if (o.setSelectionRange) { 
    o.focus(); 
    return o.setSelectionRange(pos, pos); 
    } else if (o.createTextRange) { 
    f1 = function() { 
     return o.focus(); 
    }; 
    setTimeout(f1, 10); 
    f2 = function() { 
     var range; 
     range = o.createTextRange(); 
     range.collapse(true); 
     range.moveEnd('character', pos); 
     range.moveStart('character', pos); 
     return range.select(); 
    }; 
    setTimeout(f2, 20); 
    return pos; 
    } 
} 

请检查一下,我已经在IE8,IE9 & Firefox的测试修改后的代码。

+1

我现在在IE7和IE8中测试它,它工作。 感谢你节省我的时间。 – 2012-01-12 07:47:21

2

函数f(o,pos)导致问题。尝试做出个别的功能,然后打电话给他们。有两个函数定义为同名f