測試劃詞搜尋代碼

來源:互聯網
上載者:User
<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>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.