最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

js獲取光標(biāo)位置和設(shè)置文本框光標(biāo)位置示例代碼

 更新時(shí)間:2014年01月09日 16:48:31   作者:  
本實(shí)例描述了如何用Javascript來(lái)控制和獲取文本框/文本域的鼠標(biāo)光標(biāo)位置,以下代碼兼容IE和Chrome,F(xiàn)irefox,大家參考使用吧

復(fù)制代碼 代碼如下:

<script type="text/javascript">
        function getTxt1CursorPosition(){
            var oTxt1 = document.getElementById("txt1");
            var cursurPosition=-1;
            if(oTxt1.selectionStart){//非IE瀏覽器
                cursurPosition= oTxt1.selectionStart;
            }else{//IE
                var range = document.selection.createRange();
                range.moveStart("character",-oTxt1.value.length);
                cursurPosition=range.text.length;
            }
            alert(cursurPosition);
        }

        function setTxt1CursorPosition(i){
            var oTxt1 = document.getElementById("txt2");
            var cursurPosition=-1;
            if(oTxt1.selectionStart){//非IE瀏覽器
                oTxt1.selectionStart=i;
            }else{//IE
                var range = oTxt1.createTextRange();
                range.move("character",i);
                range.select();
            }
        }

        function getTa1CursorPosition(){
            var evt =window.event?window.event:getTa1CursorPosition.caller.arguments[0];
            var oTa1 = document.getElementById("ta1");
            var cursurPosition=-1;
            if(oTa1.selectionStart){//非IE瀏覽器
                cursurPosition= oTa1.selectionStart;
            }else{//IE
                var range = oTa1.createTextRange();
                range.moveToPoint(evt.x,evt.y);
                range.moveStart("character",-oTa1.value.length);
                cursurPosition=range.text.length;
            }
            alert(cursurPosition);
        }

        function setTa1CursorPosition(i){
            var oTa2 = document.getElementById("ta2");
            if(oTa2.selectionStart){//非IE瀏覽器
                oTa2.selectionStart=i;
                oTa2.selectionEnd=i;
            }else{//IE
                var range = oTa2.createTextRange();
                range.move("character",i);
                range.select();
            }
        }
    </script>

相關(guān)文章

最新評(píng)論

深水埗区| 高邮市| 阿图什市| 栖霞市| 斗六市| 丹东市| 景德镇市| 乌恰县| 石楼县| 濉溪县| 津市市| 彝良县| 都兰县| 苗栗县| 凉城县| 临西县| 玛多县| 尚志市| 麻城市| 庆云县| 张家界市| 江川县| 上蔡县| 福建省| 宁津县| 介休市| 西充县| 绩溪县| 扶风县| 什邡市| 榆社县| 桂平市| 巨鹿县| 郁南县| 民和| 陆川县| 大城县| 嵩明县| 晋中市| 南召县| 资中县|