Input Vervollständigung
by Dini Mer
HTML
<div class="input">
<input class="bg" type="text">
<input class="user-input" type="text">
</div>
CSS
*, *:before, *:after {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.input {
position: relative;
background-color: #fff;
border: 1px solid #333;
}
.input input {
display: block;
margin: 0;
padding: 0 10px;
width: 100%;
height: 30px;
background: none;
border: 0 none;
color: #333;
}
.input input.bg {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
color: #999;
z-index: 1;
}
.input input.user-input {
position: relative;
z-index: 2;
}
JavaScript
var $input = $('input.user-input');
var $bg = $('input.bg');
$input.on('keydown', function(e) {
$bg.val('');
});
$input.on('keyup', function(e) {
if($(this).val() !== '')
$bg.val($(this).val() + 'test');
});