TypeError:$(...)。val(...)在jquery中未定义 [英] TypeError: $(...).val(...) is undefined in jquery
本文介绍了TypeError:$(...)。val(...)在jquery中未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到此错误 -
TypeError:$(...)。val(...)未定义
TypeError: $(...).val(...) is undefined
使用以下JavaScript代码:
With the following JavaScript code:
$(document).ready(function () {
$("#role").on('keyup', function(){
var error = false;
if ($("#role").val() == ""){
if($(this).attr("id") == "role"){
$("#roleError").html("Role is required");
$("#role").css("border","1px solid red");
}
error = true;
}
});
});
这是我的html代码 -
Here is my html code-
<div class="form-group">
<label class="pull-left" for="role">ROLE</label>
<input type="text" name="role" class="form-control grn-text-input"
id="role" ng-model="role.name" placeholder="Manager" required/>
<span id="roleError" class="pull-left errormsg"></span>
</div>
为什么我会收到这样的错误?
Any ideas why I get such error?
推荐答案
id Ro
的元素不存在,因此此代码失败:
The element with id Ro
doesn't exist, so this code fails:
$("#ro").val()
我认为这必须是
$("#role").val()
这篇关于TypeError:$(...)。val(...)在jquery中未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文