ユーザーがEnterキーを選択して押すと、別のテキストエリアに変更したいテキストエリアがあります。たとえば、テキストエリアがあり、ユーザーがNYのようなものを選択すると、これらの2文字をNYに変更したいとします。
私は次のようなものを持っています:
$('textarea').html('I live in NY and it\'s a great place to live');
$(window).click(function(){
var selection = selectedText();
console.log(selection);
});
function selectedText() {
var ret = '';
if (window.getSelection){
ret = window.getSelection();
} else if (document.getSelection) {
ret = document.getSelection();
} else if (document.selection) {
ret = document.selection.createRange().text;
}
return ret;
}
テキストエリアからのものか、他の場所からのものかを確認する場所がわかりません。また、テキストエリアのテキストの特定の部分を変更する方法もわかりません。