2
我想在按回車後添加一個新行。我的代碼只能添加1次。請幫忙。按回車後的jquery新行
$(function() {
$('.items:last .item-quantity').keypress(function(e) {
var keyCode, path, duplicate;
keyCode = e.keyCode || e.which;
if(keyCode == '13') {
path = '.items:last';
duplicate = $(path).clone();
duplicate.children().val(null);
$(path).after(duplicate);
$(path + ' .item-name').focus();
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="col-xs-12 items">
<input type="text" class="form-control item-name col-xs-2" placeholder="Name">
<input type="text" class="form-control item-quantity col-xs-2" placeholder="Quantity">
</div>