TEXTAREA行完全选择

本文介绍了一种通过JavaScript实现的文本选中范围调整方法。该方法主要用于在文本区域中精确定位并调整选中文本的范围,适用于需要精确编辑或处理文本的应用场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

选择其中部分字符,然后点击BUTTON查看效果

<html>
<head>
<style type="text/css">
</style>
<META http-equiv="content-type" content="text/html; charset=shift_jis">
<title>TEST</title>
</head>
<LINK rel="stylesheet" href="../css/table.css" type="text/css" id="_HPB_TABLE_CSS_ID_">
<script type="text/javascript">    

function FantinySel(){

        
var oV = 0;
        
var nV = 0;
        
var rng = document.getElementById("textAr").createTextRange();
        
        
var r1 = document.selection.createRange();
        
var r2 ; 
        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();
        }

    }

</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>
</form>
</body>
</html>
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值