当专注于输入时,得到错误:jQuery中的未捕获类型错误



我有一个输入,每次我专注于它或键入某些内容时,都会收到以下错误:

Uncaught TypeError: a.nodeName.toLowerCase is not a function
    at Array.<anonymous> (jQuery-2.1.4.min.js:2)
    at jQuery-2.1.4.min.js:2
    at f (jQuery-2.1.4.min.js:2)
    at ga.select (jQuery-2.1.4.min.js:2)
    at Function.ga [as find] (jQuery-2.1.4.min.js:2)
    at HTMLDocument.handlers (jQuery-2.1.4.min.js:3)
    at HTMLDocument.dispatch (jQuery-2.1.4.min.js:3)
    at HTMLDocument.r.handle (jQuery-2.1.4.min.js:3)

有人知道这可能意味着什么吗?

这似乎是jquery文件中错误的地方:

   filter: {
        TAG: function(a) {
            var b = a.replace(ca, da).toLowerCase();
            return "*" === a ? function() {
                return !0
            }
            : function(a) {
             // HERE
                return a.nodeName && a.nodeName.toLowerCase() === b
            }
        },

.HTML

<div class="form-group">
  <label class="col-sm-3 control-label" for="kw1">Keyword 1</label>
  <div class="col-sm-9">
    <input class="form-control" type="text" value="" id="kw1" />
  </div>
</div>

首先将节点名称解析为字符串:

a.nodeName.toString().toLowerCase();

toLowerCase(( 方法将字符串转换为小写字母。

因此,您是否尝试过将a.nodeName转换为字符串?

a.nodeName.toString().toLowerCase();

重要错误部分

Array.<anonymous>

jQuery 返回一个集合/数组

因此,您必须指定索引

a[index].nodeName.toLowerCase()

a[0].nodeName.toLowerCase()

检查下面

console.log($('div')[0].nodeName.toLowerCase()); //=>work 
console.log($('div').nodeName.toLowerCase()); // => error
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<div>
  <div>
    Hello world
  </div>
</div>

这解决了以下问题:https://stackoverflow.com/a/35579223/4031815

我们的表单中有另一个名为nodeName的输入,它与jQuery var(也称为nodeName(发生冲突,因此我将名称更改为另一件事,这解决了问题

相关内容

最新更新