2015-03-26 2 views
0

У меня возникла проблема при попытке идентифицировать INPUT с пустым значением или у которого есть только атрибут value без = "". См. Ниже мой код.Ввод формы с пустым значением

<form id='form'> 
<div class='input-field col s12'> 
    <input id='title' type='text' value> 
    <label for='title'>Job Tilte</label> 
</div> 
<div class='input-field col s12'> 
    <input type='text' id='company' value='test' /> 
    <label for='company'>Company Name</label> 
</div> 
<div class='input-field col s12'> 
    <input type='text' id='telephone' value='' /> 
    <label for='telephone'>Telephone Number</label> 
</div> 
<div class='input-field col s12'> 
    <textarea id='description' placeholder='test2'></textarea> 
    <label for='description'>About you</label> 
</div> 
<div class='input-field col s12'> 
    <input type='password' id='password' /> 
    <label for='password'>Your password</label> 
</div> 
<div class='input-field col s12'> 
    <input type='password' id='re-password' /> 
    <label for='re-password'>Confirm your password</label> 
</div> 
<input type='submit' disabled='disabled' value='Update' id='sendbutton' /> 

И это мой JQuery:

if ($('#form input').val().length !== 0) { 
     $(this).hide(); 
     } else { 
     $(this).next().addClass('active'); 
     } 

Может кто-нибудь помочь мне с этим вопросом? Спасибо заранее.

ответ

1

использование ниже код. each() вы можете получить все элементы ввода внутри #form. см DEMO

$(document).ready(function(){ 
    $('#form input').each(function(){ 
    if ($(this).val().length !== 0) { 
     $(this).hide(); 
    } else { 
     $(this).next().addClass('active'); 
    } 
    }); 
}); 
1

Вам нужно

$('#form input').each(function() { 
    if (this.value.length !== 0) { 
     $(this).hide(); 
    } else { 
     $(this).next().addClass('active'); 
    } 
}) 
Смежные вопросы