Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何设置文件上载按钮的样式_Javascript_Html_Css - Fatal编程技术网

Javascript 如何设置文件上载按钮的样式

Javascript 如何设置文件上载按钮的样式,javascript,html,css,Javascript,Html,Css,我有一个文件上传按钮,我需要文件。我目前默认使用一些预设样式 第1步。创建简单的html标记 <div class="fileUpload btn btn-primary"> <span>Upload</span> <input type="file" class="upload" /> </div> 第1步。创建简单的html标记 <div class="fileUpload btn btn-primary"

我有一个文件上传按钮,我需要文件。我目前默认使用一些预设样式


第1步。创建简单的html标记

<div class="fileUpload btn btn-primary">
    <span>Upload</span>
    <input type="file" class="upload" />
</div>

第1步。创建简单的html标记

<div class="fileUpload btn btn-primary">
    <span>Upload</span>
    <input type="file" class="upload" />
</div>
input[type=“file”]{
显示:无;
}
.自定义文件上载{
边框:1px实心#ccc;
显示:内联块;
填充:6px 12px;
光标:指针;
}

自定义上载
input[type=“file”]{
显示:无;
}
.自定义文件上载{
边框:1px实心#ccc;
显示:内联块;
填充:6px 12px;
光标:指针;
}

自定义上载
试试这个

“严格使用”;
;(功能(文档、窗口、索引)
{
var inputs=document.querySelectorAll('.inputfile');
Array.prototype.forEach.call(输入,函数(输入)
{
var label=input.nextElementSibling,
labelVal=label.innerHTML;
input.addEventListener('change',函数(e)
{
var fileName='';
如果(this.files&&this.files.length>1)
fileName=(this.getAttribute('data multiple caption')| |').replace('{count}',this.files.length);
其他的
fileName=e.target.value.split('\\').pop();
如果(文件名)
label.querySelector('span').innerHTML=fileName;
其他的
label.innerHTML=labelVal;
});
//Firefox错误修复
addEventListener('focus',function(){input.classList.add('has focus');});
addEventListener('blur',function(){input.classList.remove('has focus');});
});
}(文档,窗口,0))
input[type=“file”]{
位置:绝对位置;
排名:0;
右:0;
左:0;
底部:0;
宽度:100%;
保证金:0;
填充:0;
字号:1px;
光标:指针;
不透明度:0;
过滤器:alpha(不透明度=0);
}
.inputfile+标签范围{
宽度:200px;
最小高度:18px;
显示:内联块;
文本溢出:省略号;
空白:nowrap;
溢出:隐藏;
垂直对齐:顶部;
边框:1px实心#ccc;
}
.inputfile+标签强{
身高:100%;
颜色:#fff;
背景色:#d3394c;
显示:内联块;
}
.inputfile+标签跨度,
.inputfile+标签强{
填充:10px;
}
.inputfile+标签svg{
宽度:1米;
高度:1米;
垂直对齐:中间对齐;
填充:当前颜色;
边缘顶部:-0.25em;
右边距:0.25em;
}
.盒子{
位置:相对位置;
}

选择一个文件&hellip
试试这个

“严格使用”;
;(功能(文档、窗口、索引)
{
var inputs=document.querySelectorAll('.inputfile');
Array.prototype.forEach.call(输入,函数(输入)
{
var label=input.nextElementSibling,
labelVal=label.innerHTML;
input.addEventListener('change',函数(e)
{
var fileName='';
如果(this.files&&this.files.length>1)
fileName=(this.getAttribute('data multiple caption')| |').replace('{count}',this.files.length);
其他的
fileName=e.target.value.split('\\').pop();
如果(文件名)
label.querySelector('span').innerHTML=fileName;
其他的
label.innerHTML=labelVal;
});
//Firefox错误修复
addEventListener('focus',function(){input.classList.add('has focus');});
addEventListener('blur',function(){input.classList.remove('has focus');});
});
}(文档,窗口,0))
input[type=“file”]{
位置:绝对位置;
排名:0;
右:0;
左:0;
底部:0;
宽度:100%;
保证金:0;
填充:0;
字号:1px;
光标:指针;
不透明度:0;
过滤器:alpha(不透明度=0);
}
.inputfile+标签范围{
宽度:200px;
最小高度:18px;
显示:内联块;
文本溢出:省略号;
空白:nowrap;
溢出:隐藏;
垂直对齐:顶部;
边框:1px实心#ccc;
}
.inputfile+标签强{
身高:100%;
颜色:#fff;
背景色:#d3394c;
显示:内联块;
}
.inputfile+标签跨度,
.inputfile+标签强{
填充:10px;
}
.inputfile+标签svg{
宽度:1米;
高度:1米;
垂直对齐:中间对齐;
填充:当前颜色;
边缘顶部:-0.25em;
右边距:0.25em;
}
.盒子{
位置:相对位置;
}

选择一个文件&hellip

试试这样的方法

document.getElementById(“文件上传”).addEventListener(“更改”,函数(){
var fullPath=document.getElementById(“文件上载”).value
var filename=fullPath.replace(/^.[\\/]/,'')
document.getElementById(“status”).innerHTML=文件名;
});
。文件上传{
不透明度:0;
位置:绝对位置;
排名:0;
左:0;
高度:75px;
宽度:100%;
边框:1px纯红;
}
.文件容器{
位置:相对位置;
}
.自定义文件上载{
位置:绝对位置;
排名:0;
左:0;
}
#地位{
字体大小:25px;
颜色:红色;
字体大小:粗体;
}

在此处放置精美物品(单击我)




试试这样的方法

document.getElementById(“文件上传”).addEventListener(“更改”,函数(){
var fullPath=document.getElementById(“文件上载”).value
var filename=fullPath.replace(/^.[\\/]/,'')
document.getElementById(“status”).innerHTML=文件名;
});
。文件上传{
不透明度:0;
位置:绝对位置;
排名:0;
左:0;
高度:75px;
宽度:100%;
边框:1px纯红;
}
.文件容器{
位置:相对位置;
}
.自定义文件上载{
位置:绝对位置;
排名:0;
左:0;
}
#地位{
字体大小:25px;
颜色:红色;
字体大小:粗体;
}

在此处放置精美物品(单击我)




您可以尝试以下代码

$('input[type=“file”]”)。在('change',function()上{
$('input[type=“text”]').val($(this.val());
});
$('span')。在('click',function()上{