Jquery 如何使用纯css按钮(无图像)更改输入按钮?

Jquery 如何使用纯css按钮(无图像)更改输入按钮?,jquery,css,button,input,field,Jquery,Css,Button,Input,Field,可能重复: 我试图用css创建的按钮来更改默认的输入type=“file”按钮。这是我的html代码: <input type="file" name="name" value="" /> <a href="#" class="button">Browse</a> 此外,您可以检查它据我所知,您不能对“浏览”按钮进行样式设置。这里唯一的解决方法就是使用Z-Index在上面覆盖另一个按钮;这可能不是一个很好的做法。文件输入由操作系统呈现,它们不是HTML规

可能重复:

我试图用css创建的按钮来更改默认的输入type=“file”按钮。这是我的html代码:

<input type="file" name="name" value="" />
<a href="#" class="button">Browse</a>

此外,您可以检查它

据我所知,您不能对“浏览”按钮进行样式设置。这里唯一的解决方法就是使用Z-Index在上面覆盖另一个按钮;这可能不是一个很好的做法。

文件输入由操作系统呈现,它们不是HTML规范的一部分。

您只需将输入调整为按钮,然后编写jQuery函数以显示文件:

 <input type="button" name="name" value="Browse" class="button"/>

按照中给出的技巧构建一个。阅读它以获得解释

HTML

<div class="fileinputs">
    <input type="file" class="file" />
    <div class="fakefile">
        <a href="#" class="button">Browse</a>

    </div>
</div>
<div class="fileinputs">
    <input type="file" class="file" />
    <div class="fakefile">
        <a href="#" class="button">Browse</a>

    </div>
</div>
.button {
    display:inline;
    -moz-box-shadow:inset 0px 1px 0px 0px #fff6af;
    -webkit-box-shadow:inset 0px 1px 0px 0px #fff6af;
    box-shadow:inset 0px 1px 0px 0px #fff6af;
    background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #ffec64), color-stop(1, #f3b415) );
    background:-moz-linear-gradient( center top, #ffec64 5%, #f3b415 100% );
    filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffec64', endColorstr='#f3b415');
    background-color:#ffec64;
    -moz-border-radius:6px;
    -webkit-border-radius:6px;
    border-radius:6px;
    border:1px solid #f3b415;
    display:inline-block;
    color:#333333;
    font-family:arial;
    font-size:15px;
    font-weight:bold;
    padding:6px 24px;
    text-decoration:none;
    text-shadow:1px 1px 0px #ffee66;
}
.button:hover {
    background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #f3b415), color-stop(1, #ffec64) );
    background:-moz-linear-gradient( center top, #f3b415 5%, #ffec64 100% );
    filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#f3b415', endColorstr='#ffec64');
    background-color:#f3b415;
}
.button:active {
    position:relative;
    top:1px;
}


div.fileinputs {
    position: relative;
}

div.fakefile {
    position: absolute;
    top: 0px;
    left: 0px;
    z-index: 1;
}

input.file {
    position: relative;
    text-align: right;
    -moz-opacity:0 ;
    filter:alpha(opacity: 0);
    opacity: 0;
    z-index: 2;
}​