Bağlanma zaman lag göreceksiniz keyup
olay. Normalde için bağlama sırasında keydown
olay metin alanının değerini sen sırasında basılan tuşu belirler kadar ikinci metin-alanın değerini güncellemek olamaz bu yüzden henüz değişmedi keydown
olay. Şansımıza kullanabileceğimiz String.fromCharCode()
ikinci metin-alana yeni basılan tuşu eklemek için. Bu, tüm herhangi bir gecikme olmadan hızlı bir şekilde ikinci metin-alan güncelleme yapmak için yapılır:
$('.one').on('keydown', function(event){
var key = String.fromCharCode(event.which);
if (!event.shiftKey) {
key = key.toLowerCase();
}
$('.two').val( $(this).val() + key );
});
İşte bir demo: http://jsfiddle.net/agz9Y/2/
Bu size sadece üzerine yazarak yerine ikinci ilk değerini ekleyebilirsinizcreatives kapatıldığı ikinci neler eklemek istiyorsanız ikinci metin alanlı, ilk olarak aynı içeriğe sahip yapacaktır:
$('.one').on('keydown', function(event){
var key = String.fromCharCode(event.which);
if (!event.shiftKey) {
key = key.toLowerCase();
}
$('.two').val( $('.two').val() + $(this).val() + key );
});
İşte bir demo: http://jsfiddle.net/agz9Y/3/
Güncelleştirme
Böylece bu biraz değiştirebilir .two
eleman kendi değerini hatırlar:
$('.one').on('keydown', function(event){
var key = String.fromCharCode(event.which);
if (!event.shiftKey) {
key = key.toLowerCase();
}
//notice the value for the second textarea starts with it's data attribute
$('.two').val( $('.two').data('val') + ' -- ' + $(this).val() + key );
});
//set the `data-val` attribute for the second textarea
$('.two').data('val', '').on('focus', function () {
//when this textarea is focused, return its value to the remembered data-attribute
this.value = $(this).data('val');
}).on('change', function () {
//when this textarea's value is changed, set it's data-attribute to save the new value
//and update the textarea with the value of the first one
$(this).data('val', this.value);
this.value = this.value + ' -- ' + $('.one').val();
});