<!DOCTYPE html>
<html>
<head>
<title>Selection Start and End example</title>
<script type="text/javascript">
function SelectSomeText () {
var input = document.getElementById ("Textbox");
input.selectionStart = 4;
input.selectionEnd = 13;
}
</script>
</head>
<body>
<p><input type="text" id="Textbox" size="40" value="The text selection appears here"/></p>
<p><button onclick="SelectSomeText ()">See selection</button></p>
</body>
</html>
效果图:
[img]http://dl2.iteye.com/upload/attachment/0092/8585/a713e049-4b02-3c14-8fcd-e69a316b4f66.png[/img]
[url]http://msdn.microsoft.com/en-us/library/ie/ff974768(v=vs.85).aspx[/url]
-