<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>RunJS</title> <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script> <script type="text/javascript" > $(function(){ $("#open").click(function(){ // $("#upload").trigger("click"); var myEvent = new Event('click'); var e = document.createEvent("MouseEvents"); e.initEvent("click", true, true); //这里的click可以换成你想触发的行为 document.getElementById('upload').dispatchEvent(e); }); }); </script> </head> <body> <button id="open">Hello RunJS!</button> <input type="file" id="upload" style="display:none;"> </body> </html>
来源:https://www.cnblogs.com/jkr666666/p/11235167.html