看看这个例子:<head>
<title>Textarea select</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta name="keywords" content="php,mysql,wap,javacript,xhtml,xml,wml,svg,,,mobile" />
<script type="text/javascript">
<!--
function doS(){
var ta=document.getElementById("inTextarea")
if (document.selection) { //For IE
var sel = document.selection.createRange();
if (sel.text.length<1){alert("你没有选中文字 - -!");return false}
alert(sel.text)
}
else{ //For <a href="http://www.mozilla.org/products/firefox/" target="_blank">Firefox</a>
var startPos = ta.selectionStart
var endPos = ta.selectionEnd
if (startPos == endPos){alert("你没有选中文字 - -!");return false}
alert(ta.value.substring(startPos,endPos))
}
ta.focus()
}
//-->
</script>
</head>
<body>
<div><input type=button onclick="doS()" value="显示选中的文字"/></div>
<textarea id="inTextarea" cols=60 rows=10></textarea>
</body>
</html>
<title>Textarea select</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta name="keywords" content="php,mysql,wap,javacript,xhtml,xml,wml,svg,,,mobile" />
<script type="text/javascript">
<!--
function doS(){
var ta=document.getElementById("inTextarea")
if (document.selection) { //For IE
var sel = document.selection.createRange();
if (sel.text.length<1){alert("你没有选中文字 - -!");return false}
alert(sel.text)
}
else{ //For <a href="http://www.mozilla.org/products/firefox/" target="_blank">Firefox</a>
var startPos = ta.selectionStart
var endPos = ta.selectionEnd
if (startPos == endPos){alert("你没有选中文字 - -!");return false}
alert(ta.value.substring(startPos,endPos))
}
ta.focus()
}
//-->
</script>
</head>
<body>
<div><input type=button onclick="doS()" value="显示选中的文字"/></div>
<textarea id="inTextarea" cols=60 rows=10></textarea>
</body>
</html>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货