我在插入符号处使用jquery插件实现了非常大的脚本逻辑(http://code.google.com/p/jquery-at-caret/),但现在当我完成它时,我意识到它只适用于Firefox和Chrome,而不适用于Internet Explorer。
我意识到函数"setCaretPosition"在IE中不起作用。
我只在IE中得到了"o未定义",你可以在下面的代码片段中看到发生在79-89行插件代码中,但我不知道如何修复它。
我创建了非常小的代码片段来复制这个bug:http://www.mediafire.com/?xxt0medyci61690
我已经修改了插件中的代码
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。
函数f(o,pos)导致了此问题。尝试创建单独的函数,然后调用它们。有两个函数定义为相同的名称f
。