我遇到了limitkeypress.js和IE10的问题

时间:2013-05-10 21:52:54

标签: javascript internet-explorer

在我正在进行的项目中,我有一个文本框,用户必须输入他的名字。为了避免用户输入数字,我使用jquery.limitkeypress.js编写的Brian Jaeger库,并且在我在Internet Explorer 10中测试网站之前,每件事情都运行良好。在IE10中,您可以输入所需的所有字母,你不能像我想的那样输入数字或奇怪的符号,但当我输入一个空格然后是一个字母时,我看到字母打印到空间,然后空间消失,后者向左移动。奇怪的是,如果我在键入空格后等待30秒后输入字母,那就可以了。

2 个答案:

答案 0 :(得分:5)

jquery.limitkeypress.js有一些问题,即我建议你使用更强大的库。

http://github.com/RobinHerbots/jquery.inputmask

使用此库,您可以使用以下内容:

$(".numbers").inputmask('Regex', {
    mask: "9",
    repeat: 11,
    placeholder: ""
});

它完美适用于ie。 :)

答案 1 :(得分:1)

抱歉,我没有在几年内更新该插件,但是......

jquery.limitkeypress现在适用于IE9 +,确定选择的方式存在问题。

IE11杀死了对他们的document.selection的支持,但他们保留了我用来测试正在使用的浏览器的document.setSelectionRange ...

IE9启用了document.selectionStart和document.selectionEnd,所以我现在直接检查IE人正在使用的浏览器版本...

我添加了这个来检查IE版本:

function getSelectionStart(o) {
  if (ie < 9) {
    var r = document.selection.createRange().duplicate()
    r.moveEnd('character', o.value.length)
    if (r.text == '') return o.value.length
      return o.value.lastIndexOf(r.text)
    } else return o.selectionStart
  }
function getSelectionEnd(o) {
  if (ie < 9) {
    var r = document.selection.createRange().duplicate()
    r.moveStart('character', -o.value.length)
    return r.text.length
  } else return o.selectionEnd
}

所以我的选择功能现在看起来像这样:

public static Dictionary<int, string> Datas
    {
        get
        {
            return Enumerable.Range(0, 100) //Lots of numbers
                             .ToDictionary(x => x, x => Guid.NewGuid().ToString());
        }
    }

    [Test]
    public void MultiCacheTest([ValueSource("Datas")] KeyValuePair<int, string> item)
    {                       
        //ACT ...Yes this tests Guid.Parse 100 times
        var value = Guid.Parse(item.value);

        Assert.AreEqual(item.Value, value.ToString());           
    }