光标定位,帮忙看看
<TEXTAREA NAME= "txt " ROWS= "10 " COLS= "100% "> </TEXTAREA>
<SCRIPT LANGUAGE= "JavaScript ">
function test(obj)
{
obj.focus();
document.selection.createRange().text = "XXXXX() ";
}
</SCRIPT>
<input type= "button " id= "b " value= "Set " onclick= "test(txt) ">
如何让XXXXX()写到textarea里面之后,光标停在()里面。(|)
------解决方案-------------------- <TEXTAREA NAME= "txt " ROWS= "10 " COLS= "100% "> </TEXTAREA>
<SCRIPT LANGUAGE= "JavaScript ">
function test(obj,n)
{
document.getElementById( "txt ").value += "XXXXX() ";
obj.focus();
var rng=document.selection.createRange();
rng.moveStart( "character ", n);
rng.select();
document.getElementById( "txt ").focus();
}
</SCRIPT>
<input type= "button " id= "b " value= "Set " onclick= "test(txt,6) ">
------解决方案--------------------focus只能实现对控件的定位,不能实现对控件内容的精确定位的
------解决方案--------------------同意楼上的说法