<script type="text/javascript">
function ModifySelection ()
{
var textarea = document.getElementById("myArea");
if ('selectionStart' in textarea)
{
if (textarea.selectionStart != textarea.selectionEnd)
{
var newText = textarea.value.substring (0, textarea.selectionStart) +
"[start]" + textarea.value.substring (textarea.selectionStart, textarea.selectionEnd) + "[end]" +
textarea.value.substring (textarea.selectionEnd);
textarea.value = newText;
}
}
else
{
// IE до 9
var textRange = document.selection.createRange ();
var rangeParent = textRange.parentElement ();
if (rangeParent === textarea)
textRange.text = "[start]" + textRange.text + "[end]";
}
}
</script>
<body>
<textarea id="myArea" cols="30" spellcheck="false">1111 22222 3333 выделите текст</textarea>
<button onclick="ModifySelection ()">Обрамление</button>
</body>