`<html>
<script src="jquery-1.3.2.min.js"></script>
<script type="text/javascript">
function test(){
$('#test').selectionStart = 0;
$('#test').selectionEnd = 2;
}
</script>
<body>
<input type="button" value="登录" onclick="test()">
<input name="test" id="test" >
</body>
</html>`
注意下你的对象, js对象和jq 对象别弄混了,selectionStart 是js原生方法, 你的$('#test') 是jq对象,肯定没效果的,因jq 对象没有, 转换下就好了!
$('#test')[0].selectionStart = 0;
$('#test')[0].selectionEnd = 2;
或者
$('#test').get(0).selectionStart = 0;
$('#test').get(0).selectionEnd = 2;