我試圖構建我的表單,以便當用戶填寫輸入並按下輸入時,他們將獲得下一個輸入字段。使用jQuery驗證表單輸入與使用jQuery的鍵入輸入
我有這方面的工作在實際上還行吧顯示,未來股利只有我無法得到驗證工作......
// Form on enter next div...
$(window).load(function(){
$('footer .active input').on("keyup", function(e) {
e.preventDefault();
if (e.keyCode === 13) {
if($('footer .active input').val().length === 0){
alert('NO!');
} else {
var $activeElement = $("footer .active");
$("footer .active").next().addClass("active").removeClass('inactive');
$activeElement.removeClass("active").addClass('inactive');
}
}
});
});
form {
overflow: hidden;
width:100%; min-height:200px;
position:relative;
}
div.inactive {
position: absolute;
display: none;
width:100%;
border-bottom:1px solid rgba(255,255,255,0.3);
}
input {
padding:2.5rem 0;
font-size:4rem;
font-weight:200;
width:80%;
}
.active {
display: block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<footer>
<form action="">
<div class="input active">
<input type="text" placeholder="Who are you?" />
</div>
<div class="input inactive">
<input type="text" placeholder="What is your Email?" />
</div>
<div class="enter-btn"></div>
</form>
</footer>
這不是問題@Carsten - 我有它的工作,因爲它在移動到下一個div,我只是想驗證輸入已被填充之前,允許功能運行 – Liam
抱歉忘了添加該部分也改變了它 –
Oooh我看到了,感謝您花時間回覆 - 完美的作品! – Liam