代码简单 复制粘贴即可运行🆗 (此文于某处借鉴,如需删除,私信后即删除)
function addData(Value){ // 光标处输入
var $t = $('#iptCustom')[0]; // 插入值所在的input框
if (document.selection) {
$t.focus();
sel = document.selection.createRange();
sel.text = Value;
$t.focus();
} else if ($t.selectionStart || $t.selectionStart == '0') {
var startPos = $t.selectionStart;
var endPos = $t.selectionEnd;
var scrollTop = $t.scrollTop;
$t.value = $t.value.substring(0, startPos) + Value + $t.value.substring(endPos, $t
.value.length);
$t.focus();
$t.selectionStart = startPos + Value.length;
$t.selectionEnd = startPos + Value.length;
$t.scrollTop = scrollTop;
} else {
this.value += Value;
$t.focus();
}
}
addData("此处传入输入的值");