2016-11-25 46 views

回答

2

您可以使用Jquery和提交補充error 1日後第二刪除類。

對於過渡效果,您可以使用css3背景顏色過渡到error類。

例如,請參考下面的代碼。

$(document).ready(function() { 
 
    $("#login_button").click(function() { 
 
    var phoneEmail = $("#phone_email"); 
 
    if(!phoneEmail.val()) { 
 
     phoneEmail.addClass('error'); 
 
     setTimeout(function(){ 
 
     phoneEmail.removeClass('error'); 
 
     }, 1000); 
 
    } 
 
    }); 
 
});
input { 
 
    -webkit-transition: background-color 1s ease-out; 
 
    -moz-transition: background-color 1s ease-out; 
 
    -o-transition: background-color 1s ease-out; 
 
    transition: background-color 1s ease-out; 
 
} 
 

 
input.error { 
 
    background: #f3765b; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<form> 
 
    <input type="text" id="phone_email" placeholder="Phone or email"> 
 
    <input type="password" id="pass" placeholder="password"> 
 
    <button id="login_button">Log in</button> 
 
</form>

+0

它看起來不錯,我會嘗試添加一些漸變顏色雖然 – kilogram

+0

轉換:'背景顏色1s緩進', \t \t \t \t \t「background-color」:「red」 – kilogram

+0

@千克圖是的,你可以按照(y)修改它。 – pradeep1991singh

1

嘗試是這樣的:

//check if input is empty  
$('.someinputs').each(function(){ 
      if($(this).val() == 0 || $(this).val() == '') { 
      $(this).addClass('empty_field'); 
      } 
      else { 
      $(this).removeClass('empty_field'); 
      } 
     }); 

//this function lights field which have class '.empty_field' 
function lightEmpty(){ 
       $('.empty_field').each(function(){      
        $(this).css('border','2px solid #d8512d'); 
       }); 
       setTimeout(function(){ 
       $('.empty_field').each(function(){       
        $(this).css('border','1px solid #cdcdcd'); 
       }); 
       },1500); 
} 

//this triggers lightEmpty() 
if (emptyInputs.length != 0) 
    { 
     lightEmpty(); 
    } 

這只是改變的特定顏色的投入邊境時,你可以在setTimeout函數編寫。我想你可以找出在哪裏使用此代碼

+0

非常感謝,但我不想要邊框。以前的例子很好 – kilogram

+0

它接近我在vk.com上看到的內容 – kilogram