扩展IE下的input selectionStart selectionEnd属性
firefox有selectionStart和selectionEnd属性,指示被选择的内容的开始和结束位置,如果没有选择,则selectionStart和selectionEnd一样。IE没有selectionStart selectionEnd属性,可以使用下面的代码扩展。
原创文章,转载请注明出处:扩展IE下的input selectionStart selectionEnd属性
+展开
-HTML
<input onclick="selStart(this)" value="1,22,333,2,322,6,3321"/>
<script type="text/javascript">
function selStart(o){
if(document.selection){
o.focus();
var r = document.selection.createRange(),tr=o.createTextRange();
tr.setEndPoint('endtoend',r);
o.selectionStart=tr.text.length-r.text.length;
o.selectionEnd=tr.text.length;
}
alert(o.selectionStart+'\n'+o.selectionEnd);
}
</script>
<script type="text/javascript">
function selStart(o){
if(document.selection){
o.focus();
var r = document.selection.createRange(),tr=o.createTextRange();
tr.setEndPoint('endtoend',r);
o.selectionStart=tr.text.length-r.text.length;
o.selectionEnd=tr.text.length;
}
alert(o.selectionStart+'\n'+o.selectionEnd);
}
</script>
加支付宝好友偷能量挖...
原创文章,转载请注明出处:扩展IE下的input selectionStart selectionEnd属性