Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/438.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,我正在使用下面的代码来设置文件上载。但是在我的页面上,输入元素的宽度大于显示的实际按钮。我可以单击此不可见框中的任何位置,仍然可以打开文件浏览器。我只想点击按钮并打开它,而不是空白。我怎样才能做到这一点 你是这个意思吗 <label> <input type="file" /> <span class="file-button">Upload File</span> </label> label { disp

我正在使用下面的代码来设置文件上载。但是在我的页面上,输入元素的宽度大于显示的实际按钮。我可以单击此不可见框中的任何位置,仍然可以打开文件浏览器。我只想点击按钮并打开它,而不是空白。我怎样才能做到这一点

你是这个意思吗

<label>
    <input type="file" />
    <span class="file-button">Upload File</span>
</label>

label {
    display: inline-block;
}

label input[type="file"] {
    display: none;
}

.file-button {
    padding: 13px 20px;
    color: #fff;
    display: block;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.8em;
    background: #f00;
}

上载文件
标签{
显示:内联块;
}
标签输入[type=“file”]{
显示:无;
}
.文件按钮{
填充:13px 20px;
颜色:#fff;
显示:块;
光标:指针;
字号:500;
字号:0.8em;
背景:#f00;
}
你是这个意思吗

<label>
    <input type="file" />
    <span class="file-button">Upload File</span>
</label>

label {
    display: inline-block;
}

label input[type="file"] {
    display: none;
}

.file-button {
    padding: 13px 20px;
    color: #fff;
    display: block;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.8em;
    background: #f00;
}

上载文件
标签{
显示:内联块;
}
标签输入[type=“file”]{
显示:无;
}
.文件按钮{
填充:13px 20px;
颜色:#fff;
显示:块;
光标:指针;
字号:500;
字号:0.8em;
背景:#f00;
}

您可以隐藏文件按钮,并创建一个假的按钮来模拟它。像这样:

var fakeButton=document.getElementById('fake-file-btn');
var fileButton=document.getElementById('selectFiles');
fakeButton.addEventListener('click',函数(e){
//创建触发单击文件按钮的事件
var clickEvent=newmouseevent('click',{bubbles:true});
fileButton.dispatchEvent(单击事件);
});
#选择文件{
显示:无;
}
选择文件

您可以隐藏文件按钮,并创建一个假的按钮来模拟它。像这样:

var fakeButton=document.getElementById('fake-file-btn');
var fileButton=document.getElementById('selectFiles');
fakeButton.addEventListener('click',函数(e){
//创建触发单击文件按钮的事件
var clickEvent=newmouseevent('click',{bubbles:true});
fileButton.dispatchEvent(单击事件);
});
#选择文件{
显示:无;
}
选择文件

请共享更多html代码,这不足以重现问题,因为输入是如何工作的,元素不仅仅是按钮。这是组件的默认行为,我认为您无法按照指定的方式配置它。相反,你可能需要这样做,请分享更多的html代码,这还不足以重现问题,因为这就是输入的工作方式,元素不仅仅是按钮。这是组件的默认行为,我认为您无法按照指定的方式配置它。相反,你可能需要这样做