js觸發單擊事件(不是呼叫某元件定義的單擊函式,而是觸發,相當於你點選)
阿新 • • 發佈:2019-01-22
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>無標</title> </head> <body> <form id="form1" runat="server"> <input id="fff" type="file" size="0" onclick="javascript:onFileUpload()"/><br> <input id="bbb" type="button" value="按鈕" onclick="javascript:getonFileUpload()"/><br> <input id="ttt" type="text" value=""/><br> </br> </form> </body> </html> <script type="text/javascript"> function onFileUpload(){ alert("uuupp"); } function getonFileUpload(){ //觸發fff的單擊事件,這和直接呼叫fff定義的單擊函式是有很大區別的 //單擊時會有檔案選擇框,若只是單單呼叫定義的單擊函式,沒有檔案選擇框彈出 document.getElementById("fff").click(); document.getElementById("ttt").value=document.getElementById("fff").value; } </script>