textarea--输出选择行之前的所有文本(倒序)

< html >
< head >
< style type = " text/css " >
</ style >
< META http - equiv = " content-type "  content = " text/html; charset=shift_jis " >
< title > TEST </ title >
</ head >
< script type = " text/javascript " >     

function  FantinySel() {

        
var oV = 0;
        
var nV = 0;
        
        
var r1 = document.selection.createRange();
        
var r2 = null
        oV 
= r1.boundingHeight;
        nV 
= r1.boundingHeight;
        
if (r1.parentElement().name == "textAr"){
            
while(oV == nV){
                r2 
= r1.duplicate();
                r2.moveEnd(
"character",1);
                nV 
= r2.boundingHeight;
                
if (oV == nV){
                r1.moveEnd(
"character",1);
                }

            }

            r1.select();
        }

        oV 
= r1.boundingHeight;
        nV 
= r1.boundingHeight;
        
if (r1.parentElement().name == "textAr"){
            
while(oV == nV){
                r2 
= r1.duplicate();
                r2.moveStart(
"character",-1);
                nV 
= r2.boundingHeight;
                
if (oV == nV){
                r1.moveStart(
"character",-1);
                }

            }

            r1.select();
        }

/**/
        
if (r1.parentElement().name == "textAr"){
            output.innerHTML 
= "";
            
var rng = document.getElementById("textAr").createTextRange();
            rng.collapse();

            
if(r1.text == ""){
                r1.moveEnd(
"character",1);
            }

            
while(rng.getBoundingClientRect().bottom <= r1.getBoundingClientRect().top){
                r2 
= rng.duplicate();
                rng.moveEnd(
"character",1);
            }

            
            
if(r2 != null){
                
//output.innerHTML += "<pre>" + r2.text + "</pre>";
                var aryOutput;
                
var strOutput;
                
                aryOutput 
= r2.text.split(" ");
                strOutput 
= "";
                
                
for(i=0;i<aryOutput.length;i++){
                    strOutput 
= aryOutput[i] + " " + strOutput;
                }

                output.innerHTML 
= "<pre>" + strOutput + "</pre>";
            }

        }


    }

</ script >
</ head >
< body bgcolor =   " #ffffff " >
< form method = " post "  action = ""  name = " FMlog " >     
< table >
    
< tr >< td >
        
< input type  =  button value  =   " Config "  onclick  =   " FantinySel() " >
    
</ td ></ tr >
    
< tr >< td >
        
< textarea name  =   " textAr "  rows  =   " 5 "  cols  =   " 100 " >
123424323423
56782342423
98762342423
9876523423423
56782342423
98762342423
9876523423423
        
</ textarea >
    
</ td >
    
</ tr >
</ table >
< div id = " output " ></ div >
</ form >
</ body >
</ html >
 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值