<!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> - </title>
<script type='text/javascript' src="@bak/jquery-1.5.2.min.js"></script>
<script type='text/javascript'>
(function($){
$.fn.getVal=function(){
var a=$(this).get(0),v=$(this).val();
$(this).click(function(){
if($.browser.msie){
a.focus();var r=document.selection.createRange(),t=a.createTextRange();t.setEndPoint("endtoend",r);
p=(parseInt(t.text.length)+1);
}else{
var p=(parseInt(a.selectionStart)+1);
}
var r=new Array(),n=0;r=v.split(",");
for(i=0;i<r.length;i++){
n=n+(r[i]+'').length+1;
if(n>=p){
alert('"'+r[i]+'"|'+n+'|'+p);
break;
}
}
})
}
})(jQuery)
$(function(){
$('#c1').getVal();
});
</script>
</head>
<body>
<input value="1,22,333,2,322,6,3321" style="width:66%" id="c1">
</body>
</html>
获取文本框中焦点的位置 兼容IE,FireFox
最新推荐文章于 2018-09-18 10:34:30 发布