【发布时间】:2014-01-12 08:49:25
【问题描述】:
我希望将标准文件上传按钮provided by JQuery Mobile 修改为自定义文件上传按钮。 (见下文) 尝试了几种方法来覆盖样式,但收效甚微。 有人可以建议我如何实现这一目标吗?
标准文件上传按钮
自定义文件上传按钮
<style>
div.fileinputs {
position: relative;
}
div.fakefile {
position: absolute;
top: 0px;
left: 0px;
z-index: 1;
}
div.fakefile input[type=button] {
/* enough width to completely overlap the real hidden file control */
cursor: pointer;
width: 426px;
}
div.fileinputs input.file {
position: relative;
text-align: right;
-moz-opacity:0 ;
filter:alpha(opacity: 0);
opacity: 0;
z-index: 2;
}
</style>
<script>
$(document).on('pageinit','#address_form',function (event){
$('#upload_button').parent('.ui-btn').css('width','334%');
})
</script>
<div data-role="page" id="address_form">
<div data-role="content">
<div class='container_12'>
<div class='grid_12 fileinputs' >
<input type="file" class="file" style='opacity:0;' />
<div class="fakefile" style='padding: 1.8%;' >
<input id='upload_button' type="button" value="Upload" style='' />
</div>
</div>
</div>
</div>
</div>
【问题讨论】:
-
你尝试过什么?我认为不使用其他 jquery 代码是不可能的。
-
我在此链接上尝试了建议,但在设置按钮大小以适应响应式网页设计时遇到问题。 (我会将代码添加到我的问题中)stackoverflow.com/questions/4532733/styling-input-type-file
-
您是否尝试为上传字段添加标签,然后隐藏该字段?单击标签会激活 Safari 和 Chrome 中的字段。
标签: jquery css jquery-mobile