<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml1.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Example</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> 
<script type="text/javascript">
$(function(){
$("#file").change(function(){
var filePath=$(this).val();
$("#txt1").val(filePath);
});
});
</script>
</head>
<body>
<input type="file" id="file" />
<input type="text" id="txt1" /></body>
</html>

解决方案 »

  1.   

    自己切割下字符串  或者html5的file对象
      

  2.   


    这写法也是不行的,因为浏览器不允许读取本地文件。所以会抛出fakepath你的是载入图片,那么webkit之类的现代浏览器可以用img.onload实现。
    但低版本的IE用不了这玩意,得用document.selection.createRange().text
      

  3.   

    你实验都不实验就放上来,误导我,在FF也许可以,但在IE,谷歌是不可以的
      

  4.   

    引用一楼的稍加改动:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
        "http://www.w3.org/TR/xhtml11/DTD/xhtml1.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
        <title>Example</title>   
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> 
        <script type="text/javascript">
            $(function(){
                $("#file").change(function(){
                    var path=$(this).val();
    var path1 = path.lastIndexOf("\\");
    var name = path.substring(path1+1);
                    $("#txt1").val(name);
                });
            });
        </script>
    </head>
    <body>
        <input type="file" id="file" />
        <input type="text" id="txt1" />
     
    </body>
    </html>