js獲取光標(biāo)位置和設(shè)置文本框光標(biāo)位置示例代碼
<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>
- JavaScript自定義文本框光標(biāo)
- Javascript實現(xiàn)獲取及設(shè)置光標(biāo)位置的方法
- js光標(biāo)定位文本框回車表單提交問題的解決方法
- JS在可編輯的div中的光標(biāo)位置插入內(nèi)容的方法
- js實現(xiàn)獲取焦點后光標(biāo)在字符串后
- 在頁面中js獲取光標(biāo)/鼠標(biāo)的坐標(biāo)及光標(biāo)的像素坐標(biāo)
- js切換光標(biāo)示例代碼
- js/html光標(biāo)定位的實現(xiàn)代碼
- javascript textarea光標(biāo)定位方法(兼容IE和FF)
- JavaScript中在光標(biāo)處插入添加文本標(biāo)簽節(jié)點的詳細(xì)方法
相關(guān)文章
input+select(multiple) 實現(xiàn)下拉框輸入值
昨天做一個網(wǎng)站時,需要實現(xiàn)下拉框能夠輸入,從功能上講是要實現(xiàn)用戶在文本框輸入值時,能夠從后讀出數(shù)據(jù)彈出下拉選項2009-05-05
多種方式實現(xiàn)JS調(diào)用后臺方法進(jìn)行數(shù)據(jù)交互
幾種典型常用的方法如利用控件的AutopostBack屬性、Button提交表單等等,下面為大家分享下JS調(diào)用后臺方法進(jìn)行數(shù)據(jù)交互示例2013-08-08
JS實現(xiàn)仿FLASH效果的豎排導(dǎo)航代碼
這篇文章主要介紹了JS實現(xiàn)仿FLASH效果的豎排導(dǎo)航代碼,涉及JavaScript基于定時函數(shù)動態(tài)設(shè)置頁面元素樣式的技巧,具有FLASH變換效果,需要的朋友可以參考下2015-09-09
JS組件Bootstrap Table表格多行拖拽效果實現(xiàn)代碼
這篇文章主要介紹了JS組件Bootstrap Table表格多行拖拽效果實現(xiàn)代碼,需要的朋友可以參考下2015-12-12
滾動條的監(jiān)聽與內(nèi)容隨著滾動條動態(tài)加載的實現(xiàn)
下面小編就為大家?guī)硪黄獫L動條的監(jiān)聽與內(nèi)容隨著滾動條動態(tài)加載的實現(xiàn)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-02-02

