<head><title>无标题文档</title></head><body>
<script language="javascript">function Insert(str) {
var obj = document.getElementById('content');
if(document.selection) {
obj.focus();
var sel=document.selection.createRange();
document.selection.empty();
sel.text = str;
} else {
var prefix, main, suffix;
prefix = obj.value.substring(0, obj.selectionStart);
main = obj.value.substring(obj.selectionStart, obj.selectionEnd);
suffix = obj.value.substring(obj.selectionEnd);
obj.value = prefix + str + suffix;
}
obj.focus();
}
</script>
<table width="630" height="55" border="0" cellpadding="0" cellspacing="0">
<tr><td><label>
<textarea id="content" name="textarea" style="width:500px; height:120px;"></textarea>
</label></td></tr>
<tr><td width="567" align="left" >
<input type="button" style="cursor:hand" onclick="javascript:Insert('急')" value="急 " />
<input type="button" style="cursor:hand" onclick="javascript:Insert('发')" value="发 " />
<input type="button" style="cursor:hand" onclick="javascript:Insert('求')" value="求 " />
<input type="button" style="cursor:hand" onclick="javascript:Insert('回')" value="回 " />
<input type="button" style="cursor:hand" onclick="javascript:Insert('货')" value="货 " />
<input type="button" style="cursor:hand" onclick="javascript:Insert('至')" value="至 " />
<input type="button" style="cursor:hand" onclick="javascript:Insert('车')" value="车 " />
<input type="button" style="cursor:hand" onclick="javascript:Insert('到')" value="到 " />
<input type="button" style="cursor:hand" onclick="javascript:Insert('要')" value="要 " />
<input type="button" style="cursor:hand" onclick="javascript:Insert('在')" value="在 " />
<input type="button" style="cursor:hand" onclick="javascript:Insert('剩')" value="剩 " />
<input type="button" style="cursor:hand" onclick="javascript:Insert('空')" value="空 " />
<input type="button" style="cursor:hand" onclick="javascript:Insert('装')" value="装 " />
<input type="button" style="cursor:hand" onclick="javascript:Insert('占')" value="占 " />
<input type="button" style="cursor:hand" onclick="javascript:Insert('或')" value="或 " />
<input type="button" style="cursor:hand" onclick="javascript:Insert('节')" value="节 " />
<input type="button" style="cursor:hand" onclick="javascript:Insert('大')" value="大 " />
<input type="button" style="cursor:hand" onclick="javascript:Insert('小')" value="小 " />
<input type="button" style="cursor:hand" onclick="javascript:Insert('卸')" value="卸 " /> </td></tr>
</table>
</body>
</html>此代码有点问题,单击按钮,按钮的值就在文本域中显示,当你继续单击空白处后,再去单击按钮文本域中显示的文字不能随上次位置继续显示,而是在文本域的开始地方显示,求解!!!
<script language="javascript">function Insert(str) {
var obj = document.getElementById('content');
if(document.selection) {
obj.focus();
var sel=document.selection.createRange();
document.selection.empty();
sel.text = str;
} else {
var prefix, main, suffix;
prefix = obj.value.substring(0, obj.selectionStart);
main = obj.value.substring(obj.selectionStart, obj.selectionEnd);
suffix = obj.value.substring(obj.selectionEnd);
obj.value = prefix + str + suffix;
}
obj.focus();
}
</script>
<table width="630" height="55" border="0" cellpadding="0" cellspacing="0">
<tr><td><label>
<textarea id="content" name="textarea" style="width:500px; height:120px;"></textarea>
</label></td></tr>
<tr><td width="567" align="left" >
<input type="button" style="cursor:hand" onclick="javascript:Insert('急')" value="急 " />
<input type="button" style="cursor:hand" onclick="javascript:Insert('发')" value="发 " />
<input type="button" style="cursor:hand" onclick="javascript:Insert('求')" value="求 " />
<input type="button" style="cursor:hand" onclick="javascript:Insert('回')" value="回 " />
<input type="button" style="cursor:hand" onclick="javascript:Insert('货')" value="货 " />
<input type="button" style="cursor:hand" onclick="javascript:Insert('至')" value="至 " />
<input type="button" style="cursor:hand" onclick="javascript:Insert('车')" value="车 " />
<input type="button" style="cursor:hand" onclick="javascript:Insert('到')" value="到 " />
<input type="button" style="cursor:hand" onclick="javascript:Insert('要')" value="要 " />
<input type="button" style="cursor:hand" onclick="javascript:Insert('在')" value="在 " />
<input type="button" style="cursor:hand" onclick="javascript:Insert('剩')" value="剩 " />
<input type="button" style="cursor:hand" onclick="javascript:Insert('空')" value="空 " />
<input type="button" style="cursor:hand" onclick="javascript:Insert('装')" value="装 " />
<input type="button" style="cursor:hand" onclick="javascript:Insert('占')" value="占 " />
<input type="button" style="cursor:hand" onclick="javascript:Insert('或')" value="或 " />
<input type="button" style="cursor:hand" onclick="javascript:Insert('节')" value="节 " />
<input type="button" style="cursor:hand" onclick="javascript:Insert('大')" value="大 " />
<input type="button" style="cursor:hand" onclick="javascript:Insert('小')" value="小 " />
<input type="button" style="cursor:hand" onclick="javascript:Insert('卸')" value="卸 " /> </td></tr>
</table>
</body>
</html>此代码有点问题,单击按钮,按钮的值就在文本域中显示,当你继续单击空白处后,再去单击按钮文本域中显示的文字不能随上次位置继续显示,而是在文本域的开始地方显示,求解!!!
解决方案 »
- 请问这种弹出层该怎么实现?
- 我想用JS获取XML文件的最新5条记录应该怎么写??
- 未能解决的IE与firefox兼容问题,高分相送!!!
- 求教一个正则表达式
- 怎样提取这个变量中的值?在线等!
- 怎么得到两个整数相除的整数部分合余数部分
- 怎样实现这样的javascript;
- jscript 如何创建并使用ado对象
- 請問js中如何比較兩個時間的大小?
- 急救<a href=mailto:[email protected]?subject="主题"&body="内容">发邮件</a>请问想在body中“内容”折行怎么写?
- JavaScript能调用 framework 2.0
- [size=18px]跪求大神们帮忙啊[/size][u][/u]js
function Insert(str) {
var obj = document.getElementById('content');
if(document.selection) {
var len = obj.value.length;
obj.focus();
//接下来把光标移到结尾
var sell = obj.createTextRange();
sell.moveStart('character',len);
sell.collapse();
sell.select();
var sel=document.selection.createRange();
document.selection.empty();
sel.text = str;
} else {
var prefix, main, suffix;
prefix = obj.value.substring(0, obj.selectionStart);
main = obj.value.substring(obj.selectionStart, obj.selectionEnd);
suffix = obj.value.substring(obj.selectionEnd);
obj.value = prefix + str + suffix;
}
obj.focus();
}
</script>