ユーザーが入力を入力してEnterキーを押すと、次の入力フィールドが表示されるようにフォームを作成しようとしています。私は実際にこの作業大丈夫を持ってjQueryでkeyupでフォーム入力を検証する
それはあなたが$(document).on("keyup",'footer .active input', function(e) {})
を使用する必要があります
// 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
残念ながら、それは –
うわー、私は応答する時間を取っていただきありがとうございます - 完璧に動作します! – Liam