html

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <link rel="stylesheet" type="text/css" href="https://cdn.bootcss.com/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body>

<form class="form-inline" action="">
    <div class="container">
        <div class="row">

            <div class="form-group">
                <div class="col-sm-4 control-label">选择文件</div>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input id=\'location\' class="form-control" onclick="$(\'#i-file\').click();">
                        <label class="input-group-btn">
                            <input type="button" id="i-check" value="浏览文件" class="btn btn-primary"
                                   onclick="$(\'#i-file\').click();">
                        </label>
                    </div>
                </div>
                <input type="file" name="file" id=\'i-file\' accept=".xls, .xlsx"
                       onchange="$(\'#location\').val($(\'#i-file\').val());" style="display: none">
            </div>

        </div>
    </div>
</form>


</body>
<script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript" src="https://cdn.bootcss.com/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
</html>

效果图

更新样式

<form class="form-inline">
    <div class="form-group">
        <label for="exampleInputName2">图片</label>
        <div class="input-group">
            <input id=\'exampleInputName2\' class="form-control" onclick="$(\'#i-file\').click();">
            <label class="input-group-btn">
                <input type="button" id="i-check" value="浏览文件" class="btn btn-primary"
                       onclick="$(\'#i-file\').click();">
            </label>
        </div>
        <input type="file" name="file" id=\'i-file\' accept=".xls, .xlsx"
               onchange="$(\'#location\').val($(\'#i-file\').val());" style="display: none">
    </div>
    <button type="submit" class="btn btn-default">提交</button>
</form>

效果如下:

版权声明:本文为zhenzi0322原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/zhenzi0322/p/12073385.html