通过点击事件引用input[type=file]

xiaoxiao2021-02-27  229

通过点击事件引用file

写一个a标签做为按钮:

<a href="#" class="Upload fl" onclick=";" >本地上传<a>

再将input{type=file}隐藏:

<input id="file" type="file" name="file" title="上传头像" style="display:none;" accept="image/gif,image/jpeg,image/jpg,image/png" />

再通过js点击引用

function openBrowse(){ var ie=navigator.appName=="Microsoft Internet Explorer" ? true : false; if(ie){ document.getElementByIdx_x_x("file").click(); document.getElementByIdx_x_x("filename").value=document.getElementByIdx_x_x("file").value; }else{ var a=document_createEvent("MouseEvents");//FF的处理 a.initEvent("click", true, true); document.getElementByIdx_x_x("file").dispatchEvent(a); } }
转载请注明原文地址: https://www.6miu.com/read-8584.html

最新回复(0)