设置TextBox中光标的位置到最后(set the cursor position in a TextBox or InputText)
works in IE and FF
example:
<html xmlns="http://www.w3.org/1999/xhtml">
<script type="text/javascript">
function clik()
{
var element=document.getElementById('element');
if (document.all)
{
var range= element.createTextRange();
range.collapse(false);
range.select();
}
else {
element.focus();
var v= element.value;
element.value= '';
element.value= v;
}
}
</script>
<body>
<form id="form1" runat="server">
<input id="element" type="text" />
<input id="Button1" type="button" value="Focus" onclick="clik();" />
</form>
</body>
</html>
<script type="text/javascript">
function clik()
{
var element=document.getElementById('element');
if (document.all)
{
var range= element.createTextRange();
range.collapse(false);
range.select();
}
else {
element.focus();
var v= element.value;
element.value= '';
element.value= v;
}
}
</script>
<body>
<form id="form1" runat="server">
<input id="element" type="text" />
<input id="Button1" type="button" value="Focus" onclick="clik();" />
</form>
</body>
</html>