截图:
代码:
<input type="file" id="choosefile" style="display:none"/> <div onclick="uploadfile()" style="width:78px;height:50px;margin-left:5px;background:#00A2D4;float:left;display:block;line-height:50px;text-align:center;color:white;border-radius:3px;cursor:pointer;">选择文件</div> <div id="filename" style="line-height:70px"></div> <script type="text/javascript"> function uploadfile(){ $("#choosefile").click(); //jquery获取input file文件名 var file = $("#choosefile").val(); var fileName = getFileName(file); function getFileName(o){ var pos=o.lastIndexOf("\\"); return o.substring(pos+1); } $("#filename").html(fileName); } </script>