将光标定位到textarea的某一行的javascript代码
时间:2021-07-01 10:21:17
帮助过:27人阅读
<textarea name="ta1" rows=5 cols=50>
aaaaaaaaaaaaaa
cccccccccc
dddddddddddd
fffffffffffff
</textarea>
<input value="1" name="line">
<input type=button onclick="goL(parseInt(line.value));" value="go">
<script>
function goL(Line)
{
ta1.focus();
var v=ta1.value.split('\n');
ch=0;
for(var i=0;i<Line-1;i++)
ch+=v[i].length;
var o=ta1.createTextRange();
o.move("character",ch);
o.select();
}
</script>