Javascript 如何在不选择输入值的情况下将输入集中在加载上?

Javascript 如何在不选择输入值的情况下将输入集中在加载上?,javascript,html,css,Javascript,Html,Css,我想聚焦输入字段而不选择其中的文本。我希望光标位于末尾,并准备添加更多文本 这是我的输入字段: <input type="text" name="change" value="<?php echo $row[4]; ?>" autofocus> 尝试使用以下概念: <input id="inp1" value="abcdefg" /> <input type="button" onclick="document.getElementById('in

我想聚焦输入字段而不选择其中的文本。我希望光标位于末尾,并准备添加更多文本

这是我的输入字段:

<input type="text" name="change" value="<?php echo $row[4]; ?>" autofocus>
尝试使用以下概念:


<input id="inp1" value="abcdefg" /> 
<input type="button" onclick="document.getElementById('inp1').focus();document.getElementById('inp1').value = document.getElementById('inp1').value;" value="FOCUS" />

如果您了解jQuery,那么您可以这样做:

var input = $('input[name="change"'),
    strLen = input.val().length;
input.val(input.val());
input.focus();
input[0].setSelectionRange(strLen, strLen);
您可以从MDN


我找到了一个解决方案:

<input type="text" name="change" value="<?php echo $row[4]; ?>" autofocus onfocus="this.value = this.value;">

您允许jQuery解决方案吗?可能重复