根据浏览器判断,来定位光标的位置:
通过$.browser.msie来判断是否是IE浏览器
$(function() { $("#txt").click(function() { var position = 0; var txtFocus = document.getElementById("txt"); if ($.browser.msie) { var range = txtFocus.createTextRange(); range.move("character", position); range.select(); } else { //obj.setSelectionRange(startPosition, endPosition); txtFocus.setSelectionRange(position, position); txtFocus.focus(); } }); });
时间: 2024-10-19 21:32:36