参考如下代码:
<html>
<head>
<title>zswang 路过</title>
</head>
<body>
<textarea id="textarea1" rows="10"></textarea><br />
<input type="button" value="显示" onclick="ButtonShowClick();" />
<input type="button" value="隐藏" onclick="ButtonHintClick();" />
<script language="JavaScript">
function $(id)
{
return document.getElementById(id);
}function ButtonHintClick()
{
$("textarea1").style.display = "none";
}function ButtonShowClick()
{
$("textarea1").style.display = "";
setEditorSelStart($("textarea1"), -1);
}function setEditorSelStart(editor, selStart)
{
if (!editor) return;
editor.focus();
if (selStart < 0) selStart = editor.value.length;
if (editor.document && editor.document.selection)
{
var range = editor.createTextRange();
range.collapse(true);
range.moveStart("character", selStart);
range.select();
editor.focus();
}
else if (typeof(editor.selectionStart) != "undefined")
{
editor.selectionStart = selStart;
editor.selectionEnd = selStart;
}
}
</script>
</body>
</html>