Javascript 当关注输入时,获取错误:jQuery中的UncaughtTypeError
我有一个输入,每次我关注它或键入某个内容时,我都会出现以下错误:Javascript 当关注输入时,获取错误:jQuery中的UncaughtTypeError,javascript,jquery,Javascript,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
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)
HTML
关键词1
toLowerCase()方法仅将字符串转换为小写字母
因此,您是否尝试过将a.nodeName
转换为字符串
a.nodeName.toString().toLowerCase();
首先将节点名解析为字符串:
a.nodeName.toString().toLowerCase();
重要的错误部分
数组。
jQuery返回一个集合/数组
因此,必须指定索引
a[index].nodeName.toLowerCase()
或
检查下面
console.log($('div')[0].nodeName.toLowerCase());//=>工作
console.log($('div').nodeName.toLowerCase());//=>错误
你好,世界
这解决了问题:
表单中还有另一个名为nodeName的输入,它与一个名为nodeName的jQuery变量发生冲突,因此我将名称改为另一个名称,这就解决了您需要将html发布为well@WayneAllen完成
a.nodeName.toString().toLowerCase();
a[index].nodeName.toLowerCase()
a[0].nodeName.toLowerCase()