jquery-检查textfield中是否有文本
我有一些文本字段,我想检查其中是否有文本jquery-检查textfield中是否有文本,jquery,search,input,find,Jquery,Search,Input,Find,我有一些文本字段,我想检查其中是否有文本 <input type="text" class="inputField" id="a113" name="grp113">cm</div> 返回jQuery对象,您需要获取文本字段的值-您可以使用来获取输入字段的值 if ($(this).find('input[type="text"]').val().length > 0) { alert("there is text in the field"); } el
<input type="text" class="inputField" id="a113" name="grp113">cm</div>
返回jQuery对象,您需要获取文本字段的值-您可以使用来获取输入字段的值
if ($(this).find('input[type="text"]').val().length > 0) {
alert("there is text in the field");
} else {
alert("there is no text in the field");
}
目前,您正在检查DOM中是否有任何文本框。我怀疑你想要的是如下内容:
$(this).find('input[type="text"]').each(function () {
if ($(this).val().length > 0) {
alert("there is text in the field");
} else {
alert("there is no text in the field");
}
});
它现在什么也做不了。它会阻止我的所有其他代码运行。你觉得会是什么?谢谢你回答我的问题。
$(this).find('input[type="text"]').each(function () {
if ($(this).val().length > 0) {
alert("there is text in the field");
} else {
alert("there is no text in the field");
}
});