解决方案 »

  1.   

    <input id="demo" type="text" value="testaa.txt"><script type="text/javascript">    function setInputSelection(input, startPos, endPos) {
            input.focus();
            if (typeof input.selectionStart != "undefined") {
                input.selectionStart = startPos;
                input.selectionEnd = endPos;
            } else if (document.selection && document.selection.createRange) {
                // IE branch
                input.select();
                var range = document.selection.createRange();
                range.collapse(true);
                range.moveEnd("character", endPos);
                range.moveStart("character", startPos);
                range.select();
            }
        }    window.onload = function() {
        var ele = document.getElementById("demo");
        var end = ele.value.indexOf('.');
            setInputSelection(ele, 0, end);
        };</script>
      

  2.   

    刚才试了一下可以,但是有bug,如果文件名里面有“.”不行了