1、效果图:
2、js实现:
<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
//点击按钮后将值赋值给input框
//记录下所点击的input框
var lastInput = null;
$(function() {
var inputs = document.getElementsByTagName("input");
for (i = 0; i < inputs.length; i++) {
if (inputs[i].type.toLowerCase() == "text") {
inputs[i].onfocus = function () {
lastInput = this;
}
}
}
});
//点击按钮进行赋值
function AddContent(str) {
if (lastInput) {
lastInput.focus();
}
if (typeof document.selection != "undefined") {
document.selection.createRange().text = str;
}
else {
lastInput.value = lastInput.value.substr(0, lastInput.selectionStart) + str + lastInput.value.substring(lastInput.selectionStart, lastInput.value.length);
}
}
</script>
</head>
<body>
<form>
<input id="Text1" type="text" />
<input id="Text2" type="text" />
<input id="Text3" type="text" />
<input id="Text4" type="text" />
<input id="Text5" type="text" />
<input id="Text6" type="text" />
<input type="button" onclick="AddContent('插入内容')" value="插入" />
</form>
</body>
</html>