当我试图识别带有空值的输入时,或者在没有="“的情况下只获得值属性时,我遇到了问题。请看下面我的代码。
<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');
}有人能帮我解决这个问题吗?在此之前,非常感谢您。
发布于 2015-03-26 07:50:25
使用下面的代码。每个() --您可以在#表单中获取所有输入元素。请参阅演示
$(document).ready(function(){
$('#form input').each(function(){
if ($(this).val().length !== 0 ) {
$(this).hide();
} else {
$(this).next().addClass('active');
}
});
});发布于 2015-03-26 07:51:15
你需要
$('#form input').each(function () {
if (this.value.length !== 0) {
$(this).hide();
} else {
$(this).next().addClass('active');
}
})https://stackoverflow.com/questions/29273262
复制相似问题