3
关注
1817
浏览

“.click();”触发器“onchange”

为什么被折叠? 0 个回复被折叠
Yannyezixin 未验证用户 用户来自于: 广东省
2020-09-16 09:28

注:这只是为了说明的目的。您必须根据需要修改代码。当表单提交可能会显示错误,因为我们发布到一些随机的网址。

所以,让我们试着打破这个:

function showFile(){ 
 
    // lets trigger the file click as its hidden. 
 
    document.getElementById('fileControl').click(); 
 
} 
 

 

 
function sub(){ 
 
// check if your user has selected any file? 
 
if(document.getElementById('fileControl').files.length > 0){ 
 
// if you are curius to see your files log this 
 
//console.log(document.getElementById('fileControl').files); 
 
// do post your form here by 
 
    document.getElementById('testForm').submit(); 
 
} 
 
}
 
 
<form method="post" action="example.com" id="testForm"> 
 
 
 
<input type="file" id="fileControl" onchange="sub();" style="display:none;"> 
 
 
 
<input type="button" id="btn" value="open" onclick="showFile();"> 
 
form>

qufo 未验证用户 用户来自于: 广东省
2020-09-16 02:13

提交

关于作者

问题动态

发布时间
2020-09-15 15:51
更新时间
2022-09-15 15:52
关注人数
3 人关注
个人工作笔记 Powered BY WeCenter V4.1.0 © 2024 粤ICP备2020123311号