TextArea里,如果没有选择完一行,怎么让它强制把该行选择完?(UP者有分)

ccccffff 2006-10-13 03:31:32
要求如下:1,我只选择了第一行的某个数字,那么alert的时候,要把第一行所有的数字alert出来..
2,如果选择多行,最后一行没有选择完毕,那么最后一行的全部的数字也要被alert出来
3,选择多行后,能够不受滚动条的影响
代码如下:

<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 start_fresh(){
var rng = document.getElementById("textAr").createTextRange();
var r1 = document.selection.createRange();
alert( r1.text );
}
</script>
</head>
<body bgcolor= "#ffffff">
<form method="post" action="" name="FMlog">
<table>
<tr><td>
<input type = button value = "Config" onclick = "start_fresh()">
</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>
...全文
283 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
fantiny 2006-10-13
  • 打赏
  • 举报
回复
<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 start_fresh(){

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 = "start_fresh()">
<input type = button value = "Config" onclick = "newHighlite( document.FMlog.textAr)">
</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>
ccccffff 2006-10-13
  • 打赏
  • 举报
回复
菜鸟,你的代码还有点问题。。

比如选择了某一行的中间的几个数字,后面的出来了,前面的却没有出来啊
fantiny 2006-10-13
  • 打赏
  • 举报
回复
<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 start_fresh(){

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();
}
}
</script>
</head>
<body bgcolor= "#ffffff">
<form method="post" action="" name="FMlog">
<table>
<tr><td>
<input type = button value = "Config" onclick = "start_fresh()">
<input type = button value = "Config" onclick = "newHighlite( document.FMlog.textAr)">
</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>
ccccffff 2006-10-13
  • 打赏
  • 举报
回复
.................
ccccffff 2006-10-13
  • 打赏
  • 举报
回复
说的容易,做的难~~~

我要代码~~
kc_ren 2006-10-13
  • 打赏
  • 举报
回复
那用正则表达式吧 ~
ccccffff 2006-10-13
  • 打赏
  • 举报
回复
...........
没人了么?
jom_ch 2006-10-13
  • 打赏
  • 举报
回复
UP
liufei8463 2006-10-13
  • 打赏
  • 举报
回复
^-^
myvicy 2006-10-13
  • 打赏
  • 举报
回复
&_&
ccccffff 2006-10-13
  • 打赏
  • 举报
回复

我不要select阿
一定只能textarea的
kc_ren 2006-10-13
  • 打赏
  • 举报
回复
<select multiple="true" id="textAr">
<option>123424323423</option>
<option>56782342423</option>
<option>98762342423</option>
<option>2342324</option>
<option>3423424</option>
<option>4554645646</option>
</select>
<script language="JavaScript">
<!--
var textAr = document.getElementById("textAr")
var arrTextAr = textAr.options
alert(arrTextAr.length)
//-->
</script>
根据 arrTextAr.length 的长度 做相应的操作~
hbhbhbhbhb1021 2006-10-13
  • 打赏
  • 举报
回复
<select name="select1" multiple>
<option>123424323423</option>
<option>56782342423</option>
<option>98762342423</option>
<option>9876523423423</option>
<option>56782342423</option>
<option>98762342423</option>
<option>9876523423423</option>
</select>
<input name="button1" type="button" value="config" onclick="show()">
<script language=javascript>
function show()
{
var objs=document.getElementById("select1").options
str=""
for(var i=0;i<objs.length;i++)
{
if(objs[i].selected)
{
str+=objs[i].text+"\r\n"
}
}
alert(str)
}
</script>
hbhbhbhbhb1021 2006-10-13
  • 打赏
  • 举报
回复
<select name="select1" multiple>
<option>123424323423</option>
<option>56782342423</option>
<option>98762342423</option>
<option>9876523423423</option>
<option>56782342423</option>
<option>98762342423</option>
<option>9876523423423</option>
</select>
ccccffff 2006-10-13
  • 打赏
  • 举报
回复
怎么样的应该?
kc_ren 2006-10-13
  • 打赏
  • 举报
回复
应该用列表框做吧

87,922

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧