我有一個文本字段,我檢查以確保提交前文本字段不是空的,它工作正常。如何確保只有一個文本字段不是空的?
如何確保它只檢查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