我有一个文本字段,我检查以确保提交前文本字段不是空的,它工作正常。如何确保只有一个文本字段不是空的?
如何确保它只检查id =“名称”文本字段不为空并忽略其他文本字段。
<input type="text" class="form-control" id="Name" aria-label="Name" placeholder="Name" required >
<input type="text" class="form-control" id="address" aria-label="address" placeholder="address">
<input type="text" class="form-control" id="zip" aria-label="zip" placeholder="zip" >
JS
$('input:text').val().length;
你的意思'$( '#姓名')VAL()长;'。? – vlaz
'$('#Name')。val()。length;' – andrew
使用正确的选择器作业。请参阅[这里](http://www.w3schools.com/jquery/jquery_ref_selectors.asp)以获取jQuery选择器列表。正如其他人指出'$('#Name')'会选择你想要的元素。 – Theo