关于javascript的焦点问题(在线求解!!!)
我有一个TextBox控件 在它里面输入: 123.456
然后,我把[鼠标焦点]放到[小数点]前面或后面
如: 12[鼠标焦点]3.456 或 123.[鼠标焦点]456
用javascript 怎么知道 现在的[鼠标焦点]在[小数点]的前面还是后面
请大家指教!
------解决方案--------------------那个叫光标
<!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 " lang= "gb2312 ">
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 " />
<meta http-equiv= "Content-Language " content= "zh-cn " />
<meta content= "all " name= "robots " />
<meta name= "Author " content= "huobazi@aspxboy.com ,サ銧ミラモ " />
<meta name= "Copyright " content= "www.AspxBoy.Com,ラヤモノー貶ィ,ネホメ籏ェヤリ. " />
<meta name= "Description " content= "www.AspxBoy.Com " />
<meta name= "Keywords " content= "www.AspxBoy.Com,サ銧ミラモ,huobazi " />
<title> New New Document </title>
<script language= "javascript ">
function a(){
document.getElementById( 'x ').focus();
var oRange=document.selection.createRange();
oRange.move( "character ",4);
oRange.select();
}
</script>
</head>
<body>
<input type= "text " value= "111.2232 " id= "x " />
<br/>
<button onclick= "a(); "> Click </button>
</body>
</html>
------解决方案-------------------- <html>
<textarea id=demo cols=50>
中文abcdefghijklmnopqrstuvwxyz
</textarea>
<br> <input type=button onclick=get(demo) value=get>
<script>
function get(oTextarea){
var qswh= "@#%#^&#*$ "
oTextarea.focus();
rng=document.selection.createRange();
rng.text=qswh;
var tmp=oTextarea.value.indexOf(qswh)
rng.moveStart( "character ", -qswh.length)
rng.text= " ";
alert(tmp);
}
</script>
</html>