<html>
<body>
<script language="javaScript">
function logCart(obj)
{
if (obj.createTextRange)
obj.logPos = document.selection.createRange().duplicate();
}
function insertAtCaret (objit, text)
{
if (objit.logPos && objit.createTextRange)
{
var logPos = objit.logPos;
logPos.text = logPos.text.charAt(logPos.text.length - 1) == ' ' ? text + ' ' : text;
}
else
{
objit.value = text;
}
}
function insertText()
{
if (window.event.keyCode == 9)
{
var sv = "-【已解决】-";
var t = document.getElementById('txtArea');
if (t.logPos)
{
insertAtCaret(t, sv);
}
else
{
sv = "\n" + sv;
t.value += sv;
}
return false;
}
else
{
return true;
}
}
</script>
输入时按tab键,将在光标处加入一个要加入的字符串,使用了记录位置,累死我了. :( 终于搞定了!!!<br>
给大家留着用吧.不知道原来有没有人用过该方法.<br><br>
<textarea rows="10" name="Log" cols="80" id="txtArea"
ONSELECT="logCart(this);"
ONCLICK="logCart(this);"
ONKEYUP="logCart(this);"
ONKEYDOWN="return insertText();" >
ffffffffffffffffffffffffffffffffffddddddddddddddddddddddddddddddddddssssssssssssssssssssssssssssssssss
</textarea>
</body>
</html>