java怎么选中一正行_如何选中滚动文本框从某一行到某一行

//=======================================

//功能: 滚动文本框精确位置定位

//输入参数:

// self   滚动文本框对象

// _startLine  开始行数

// _endLine  结束行数

// _startPoint 开始行数的开始位置

// _endPoint  结束行数的结束位置

//调用方法:

// ①同一行,从开始位置到结束位置:

//   selToLinePoint(self, 2, 2, 0/1, 0)

// ②不同一行,从某一开始位置到结束位置:

//   selToLinePoint(self, 2, 4, 3, 0)

// ③不同一行,从某一开始位置到某一结束位置:

//   selToLinePoint(self, 2, 4, 3, 9)

//=======================================

function selToLinePoint(self, _startLine, _endLine, _startPoint, _endPoint, _len){

var src = self;

var oTR = self.createTextRange();

var text = self.innerText;

var textLength = text.length;

conts = [0];

startx = src.createTextRange().getClientRects()[0].left;

starty = src.createTextRange().getClientRects()[0].top;

stepy = 3;   //光标向下移动的步长,不能大于textarea中的字高

currentScr = 0;  //当前滚动条位置

stepScr = 30;  //滚动条向下滚动的步长,不能大于textarea的高度

while(1){

src.scrollTop = currentScr

currenty = starty

while(1){ //光标从textarea内容的开头开始向下移动,遍历各行,在conts[]中记下各换行位置

oTR.moveToPoint(startx, currenty)

oTR.moveEnd("character", textLength)

var _oTR_Line_Length = oTR.text.length;

cont = textLength - _oTR_Line_Length;

if (cont >= textLength){

break

}

if (cont>conts[conts.length - 1]){

conts[conts.length] = cont

}

currenty += stepy

}

if (currentScr >= src.scrollHeight){

break

}

currentScr += stepScr;

}

if (_endLine == "")

_endLine = _startLine;

_startLine = parseInt(_startLine);

_endLine = parseInt(_endLine);

if (isFinite(_startLine) && isFinite(_endLine) && _startLine > 0 && _endLine > 0){

//检查参数有效性

if (_startLine > conts.length || _endLine > conts.length){

alert("总共只有" + conts.length + "行,请检查后重试。");

return;

}

//如果结束行在开始行之前,强行调整参数

if (_endLine < _startLine){

_endLine = _startLine;

end.value = _endLine;

}

src.scrollTop = 0;

oTR.moveToPoint(startx, starty);  //光标回到textarea内容的开头

st = conts[_startLine - 1];

if (st > _startPoint){

st = st + _startPoint;

}else{

var _rightTextLen = 0;

for (var m = 0; m < conts.length; m++){

if (conts[m] < _startPoint){

_rightTextLen = _startPoint - conts[m];

st = _startPoint - _rightTextLen;

if (_endLine == _startLine){

_endLine++;

}

}else{

break;

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值