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