• 测试划词搜索代码


    <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>




  • 相关阅读:
    IDEA 使用 Gradle 创建 Java 项目
    Java HttpsUnits 工具类实现 Https
    Android Thread 常用方法
    Android Handler、Message 常用方法
    Android 透明导航键遮挡布局
    Android 通过 JDBC 连接远程数据库
    python 连接数据库
    备份及更新 Portainer
    secureCRT免密码登陆Linux
    Linux vi 编辑器常见命令的使用
  • 原文地址:https://www.cnblogs.com/wangxiang/p/916356.html
Copyright © 2020-2023  润新知