जब आप के लिए बाध्य अंतराल देखेंगे keyup
घटना। आप सामान्य रूप से करने के लिए बाध्य जब keydown
घटना पाठ क्षेत्र के मूल्य अभी तक तो आप दूसरा पाठ क्षेत्र के मूल्य जब तक आप कुंजी के दौरान दबाए निर्धारित अद्यतन नहीं कर सकते नहीं बदला है keydown
घटना। हमारे लिए भाग्यशाली हम उपयोग कर सकते हैं String.fromCharCode()
दूसरा पाठ क्षेत्र के लिए हाल में दबाया कुंजी संलग्न करने के लिए। यह सब किसी भी अंतराल के बिना जल्दी से दूसरा पाठ क्षेत्र अद्यतन बनाने के लिए किया जाता है:
$('.one').on('keydown', function(event){
var key = String.fromCharCode(event.which);
if (!event.shiftKey) {
key = key.toLowerCase();
}
$('.two').val( $(this).val() + key );
});
यहाँ एक डेमो है: http://jsfiddle.net/agz9Y/2/
यह कर देगा दूसरा पाठ क्षेत्र, पहले एक के रूप में एक ही सामग्री है, तो आप क्या में दूसरे के लिए पहली बार है तुम सिर्फ अधिलेखन के बजाय दूसरे के लिए पहली बार के मूल्य को जोड़ सकते हैं संलग्न करना चाहते हैं:
$('.one').on('keydown', function(event){
var key = String.fromCharCode(event.which);
if (!event.shiftKey) {
key = key.toLowerCase();
}
$('.two').val( $('.two').val() + $(this).val() + key );
});
यहाँ एक डेमो है: http://jsfiddle.net/agz9Y/3/
अद्यतन करें
आप इस एक सा बदल सकते हैं ताकि .two
तत्व अपने स्वयं के मूल्य को याद रखता है:
$('.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();
});