国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

如何選中滾動文本框從某一行到某一行

2019-11-18 15:35:33
字體:
來源:轉載
供稿:網友

//========================
//功能: 滾動文本框精確位置定位
//輸入參數:
// 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;
    }
   }



發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 武功县| 铜川市| 噶尔县| 尖扎县| 阿拉善左旗| 固镇县| 泽普县| 卢湾区| 信宜市| 偏关县| 高尔夫| 温泉县| 凤翔县| 德庆县| 昌平区| 资溪县| 海伦市| 芦山县| 宁远县| 黄龙县| 宁德市| 永德县| 望城县| 沽源县| 阿巴嘎旗| 新津县| 海伦市| 天祝| 潞城市| 高州市| 邵阳市| 桑日县| 安吉县| 江山市| 丰镇市| 涪陵区| 五常市| 平遥县| 湘潭县| 昌邑市| 乐昌市|