根據瀏覽器判斷,來定位光標的位置:瀏覽器
經過$.browser.msie來判斷是不是IE瀏覽器 spa
$(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(); } }); });