小码问答,有问必答!

2021-03-08 11:10

点击div,打开文件选择对话框,选择上传文件

2021-03-08 11:10 回答了这个问题

<html>
    <head>
        <title>万码学堂wanmait</title>
        <meta http-equiv="author" content="万码学堂wanmait">
        <style type="text/css">
            #file{
                display: none;
            }
            
            #div{
                width: 300px;
                height: 50px;
                background-color: aquamarine;
                border: 1px solid black;
                border-radius: 10px;
                text-align: center;
            }
        </style>
    </head>
    <body>
        <div id="div" onclick="openFile()">
           上传文件
            <input id="file" type="file">
        </div>
        
        <script type="text/javascript">
            function openFile()
            {
                document.getElementById("file").click();
            }
        </script>
    </body>
</html>


0条评论

我要评论