在输入文本框中的值时,当我在输入值之间输入值时,光标会自动移动到值的末尾。如何在使用javascript键入时避免光标移回
<!DOCTYPE html>
<html>
<body>
<script>
function truncate(x) {
if(x.value.length > 0)
{
x.value = x.value.replace(/^\s+/, '');
}
}
</script>
<input id="otherText" onkeyup="javascript:truncate(this);" maxlength="12" type="text"/>
</body>
</html>
[更改输入值的可能重复,同时还允许用户键入](http://stackoverflow.com/questions/72171 76 /改变输入值,而-静止允许最用户到型);我认为有更多类似的,但我找不到它们 – Bergi 2013-03-07 14:07:00