<HTML>
<head>
<scripttype="text/javascript"src="script/jquery-1.6.2.min.js"></script>
<scripttype=‘text/javascript‘>
functionselectFile(){
//触发文件选择的click事件
$("#file").trigger("click");
//其他code如alert($("#file").attr("value"))
}
/*获取文件的路径,用于测试*/
functiongetFilePath(){
alert($("#file").attr("value"));
}
</script>
</head>
<body>
<!--给这个input设置样式隐藏,切忌不可用display控制隐藏,可能不能跨浏览器-->
<inputtype="file"id="file"onchange="getFilePath()"
style="filter:alpha(opacity=0);opacity:0;width:0;height:0;"/>
<buttononclick="selectFile();">selectfile</button>
<buttononclick="getFilePath()">getFilePath</button>
</body>
</html>
|