method replaceSelection

void replaceSelection(string text);

Argumente

Zurückgegebener Wert

This method replaces the given selection in the edit control with the provided text. If no selection is present within the edit control the provided text is inserted using the current caret position as the starting location.
function ReplaceWord(editBx, repWord, repWordWith)
{
    if (editBx && repWord && repWordWith)
    {
        var txtValue = editBx.value;
        var startIdx = txtValue.indexOf(repWord);
        if (startIdx != -1)
        {
            editBx.setSelection(startIdx, startIdx + repWord.length);
            editBx.replaceSelection(repWordWith);
        }
    }
}