<script>
document.body.onload = tt;
function tt()
{
alert('dddddddd');
}
var b;
function te() //onselect事件
{
b=1;
}
function a() //onmouseup事件
{
if (b==1){
alert(document.selection.createRange().text);
b=0;
}
}
</script>
<body onselect ="javascript:te();" onmouseup ="javascript:a();">
onselectstart ="alert('開始');"
onmouseup="alert(document.selection.createRange().text);"
//firefox使用 window.getSelection()
網頁測試測試測試才兒時才扼殺
<br>
dddddddddddddddd
<SCRIPT LANGUAGE="JavaScript">
function SelText(){
document.selection.createRange();
document.all.TestText.value = unescape(document.selection.createRange().text);
alert("選區左側寬度:"+ document.selection.createRange().boundingLeft);
alert("選區上方高度:" + document.selection.createRange().boundingTop);
alert("選區高度:" + document.selection.createRange().boundingHeight);
alert("選區寬度:" + document.selection.createRange().boundingWidth);
}
</script>
<input type="text" id="TestText" name="TestText" value="" accesskey="A">
<input type="button" name="btnTest" value="Test" onclick="SelText()">
<hr>
對象: document.selection.createRange(); 返回TextRange 對象<br>
TextRange 屬性<br>
boundingHeight 擷取綁定 TextRange 對象的矩形的高度。 <br>
boundingLeft 擷取綁定 TextRange 對象的矩形左邊緣和包含 TextRange 對象的左側之間的距離。 <br>
boundingTop 擷取綁定 TextRange 對象的上邊緣和包含 TextRange 對象的頂邊之間的距離。 <br>
boundingWidth Retrieves the width of the rectangle that bounds the TextRange object. <br>
htmlText 擷取綁定 TextRange 對象的矩形的寬度。 <br>
offsetLeft 擷取對象相對於版面或由 offsetParent 屬性指定的父座標的計算左側位置。<br>
offsetTop 擷取對象相對於版面或由 offsetTop 屬性指定的父座標的計算頂端位置。 <br>
text 設定或擷取範圍內包含的文本。 <br>
</body>