目前共有5篇帖子。 內容轉換:不轉換▼
 
點擊 回復
365 4
【英文资料】用jQuery在火狐浏览器下移动文本框的光标
一派護法 十九級
1樓 發表于:2014-9-14 08:17
一派護法 十九級
2樓 發表于:2014-9-14 08:23
一派護法 十九級
3樓 發表于:2014-9-14 08:24
不知phpMyAdmin里面是怎么实现的
一派護法 十九級
4樓 發表于:2014-9-14 08:32
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script>
function GetCursorPosition()
{
    // HERE txt is the text field name
    var obj=document.getElementById('textarea');
    var CurPos = 0;
    
    //FOR IE
    if (document.selection)
    {
        obj.focus ();
        var Sel = document.selection.createRange();
        Sel.moveStart ('character', -obj.value.length);
        CurPos = Sel.text.length;
    }
    // For Firefox
    else if (obj.selectionStart == '0')
        CurPos = obj.selectionStart;
    return CurPos;
}

function SetCursorPosition(pos)
{
    // HERE txt is the text field name
    var obj=document.getElementById('textarea');
    
    //FOR IE
    if(obj.setSelectionRange)
    {
        obj.focus();
        obj.setSelectionRange(pos,pos);
    }
    
    // For Firefox
    else if (obj.createTextRange)
    {
        var range = obj.createTextRange();
        range.collapse(true);
        range.moveEnd('character', pos);
        range.moveStart('character', pos);
        range.select();
    }
    
    
}
</script>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
  <textarea name="textarea" id="textarea" cols="45" rows="5">Basically when we want to create an editor like interface then set or get cursor postion is one of the most important task. Here i want to share two cross-browser supported javascript methods which will meet your requirements To Set cursor position into a TextArea & To Get cursor position from TextArea:</textarea>
  <br />
  <br />
  <input type="button" name="button" id="button" value="Button" onclick="SetCursorPosition(8)" />
</form>
</body>
</html>

这个程序可以在firefox下正常设置光标位置
一派護法 十九級
5樓 發表于:2014-9-14 08:34

回复:4楼

opera浏览器下正常
ie也正常
chrome也正常

回復帖子

內容:
用戶名: 您目前是匿名發表
驗證碼:
(快捷鍵:Ctrl+Enter)
 

本帖信息

點擊數:365 回複數:4
評論數: ?
作者:巨大八爪鱼
最後回復:巨大八爪鱼
最後回復時間:2014-9-14 08:34
 
©2010-2024 Arslanbar Ver2.0
除非另有聲明,本站採用創用CC姓名標示-相同方式分享 3.0 Unported許可協議進行許可。