g.nodeName is undefined
g.nodeName is undefined
我正在将登录/注册页面转换为使用Ajax/jQuery。 因此,这两种形式之间有许多通用的验证功能。 我使用 jQuery 的一个领域是根据输入向用户输出错误消息。 虽然表单共享相似的元素 ID,但类名不同。
所以为了检查用户名,我有
if ($(":input").is('.registerName')){
//Username belongs to the registration form, so check if current entry is
//valid and not taken. Output error message otherwise
} else {
//username belongs to the login form, so check if current entry exists in database
//output username/password error depending on catch
}
我经历了一些奇怪的事情。
首先,上面的代码返回一个g.nodeName is undefined error
。 如果我将初始条件更改为
if ($("input#username").is('.registerName'))
同样的错误出现在Firebug中。
然而
if ($("#username").is('.registerName'))
和
if ($("#username").hasClass('registerName))
两者都失败,登录验证部分执行。
那么,如何在没有g.nodeName未定义错误的情况下根据类名执行正确的代码块呢?
编辑
澄清一下 - 同一页面上没有两种表格。 代码功能在javascript中。 我指的是不同页面上调用相同JS函数的两个单独的HTML表单,唯一的区别是错误消息输出中的文本。
编辑 2
JFiddle 示例:这里
文本框 onclear 不适用于小提琴,但我认为您可以了解我正在尝试做的事情的要点。
我无法重现您遇到的确切问题,请尝试
if ($(this).is('.registerName'))
相反。这样你就会知道它只查看发生keyup
事件的特定元素。 $(':input')
将在页面上查找所有输入。
相关文章:
- Jquery - table.row(tr) is undefined
- noty.js is returning undefined
- $routeParams is undefined
- Angular js $scope is Undefined
- $scope is coming as undefined
- Angular - $cookies is undefined
- TypeError: e is undefined - javascript
- “google.maps.MapTypeId is undefined”在FF 14中使用GMAP3时
- chrome.storage.local["mykey"] is undefined
- 回调在 Angular2/Firebase 中生成“TypeError: this is undefined”
- KendoWindow .visible(); is undefined?
- jQuery .forEach() 导致错误,“undefined is not a function”
- 使用“flickrnode”API时出现“TypeError: undefined is not a function”
- "undefined is not a function" onSuccessHandler
- 莫名其妙的“Undefined is not a function”错误 — 由“getElementsById”引起
- Angular js 在传递 promise 时$asyncValidator“Undefined is not a f
- undefined is not a function when evaluating 'this.batman
- “uncatch TypeError: undefined is not a function” 在使用 str.ind
- 谷歌地图API(使用gmapsjs), setCenter抛出“undefined is not a function”
- 在骨干应用视图中出现" Uncaught TypeError: undefined is not a function