表单的文件域file隐藏
div加点击事件
点击div调用文件域file的click()方法
代码如下:
<html>
<head>
<title>万码学堂wanmait</title>
</head>
<style type="text/css">
#file{
display: none;
}
#div{
width: 300px;
height: 50px;
border: 1px solid black;
border-radius: 10px;
text-align: center;
}
</style>
<body>
<div id="div" onclick="openFile()">
上传文件
<input type="file" id="file">
</div>
<script type="text/javascript">
function openFile()
{
document.getElementById("file").click();
}
</script>
</body>
</html>

0条评论
点击登录参与评论