插件中的jquery插件在IE中不起作用

时间:2012-01-12 06:54:47

标签: javascript jquery jquery-plugins

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

我意识到函数“setCaretPosition”是在IE中无效的函数。

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

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

2 个答案:

答案 0 :(得分: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 :(得分:2)

函数f(o,pos)导致问题。尝试制作单独的功能,然后调用它们。有两个函数使用相同的名称f定义。

相关问题