2012-01-15 10 views

答えて

1

ジャバスクリプト例:

document.getElementById('test').onkeyup = function(oEvent) { 
    if (typeof oEvent == 'undefined') oEvent = window.event;   // IE<9 fix 
    if (oEvent.keyCode != 32) return;  // stop if character is not the space 
    if (/@USERNAME /.test(this.value)) {  // check if @-template is available 
     this.value = this.value.replace(/@USERNAME /g, 'Dirk '); // replace it 
    } 
} 

またthis jsfiddleを参照してください。

=== UPDATEの===ここでjQueryの代替

$('#test').keyup(function(oEvent) {     // set (keyup) event handler 
    if (oEvent.keyCode != 32) return;  // stop if character is not the space 
    if (/@USERNAME /.test($(this).val())) { // check if @-template is available 
     $(this).val($(this).val().replace(/@USERNAME /g, 'Dirk ')); // replace it 
    } 
}); 

またthis jsfiddleを参照してください。

0

おそらく、onkeypressイベントをスペースバーを押すと試すことができます。ここで

関連する問題