console
let oTxt = document.getElementById('txt');
let oBtn = document.getElementById('btn');
let index = 0;
oBtn.onclick = function (e) {
e.preventDefault();
const selectionStart = oTxt.selectionStart;
const firstStr = oTxt.value.substr(0, selectionStart);
const lastStr = oTxt.value.substr(selectionStart);
oTxt.value = firstStr + 123465 +lastStr;
oTxt.selectionStart = selectionStart + 6;
oTxt.selectionEnd = selectionStart + 6;
}
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<body>
<input type="text" value="测试的文字" id="txt">
<button id="btn">设置焦点</button>
</body>
</html>