将光标定位到textarea的某一行的javascript代码
人气:0
<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>
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>
加载全部内容