mickeyort 发表于 2020-4-24 16:30:47

js触发单击事件(不是调用某组件定义的单击函数,而是触发,相当于你点击)

<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" οnclick="javascript:onFileUpload()"/><br>
<inputid="bbb" type="button" value="按钮" οnclick="javascript:getonFileUpload()"/><br>
<inputid="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>


页: [1]
查看完整版本: js触发单击事件(不是调用某组件定义的单击函数,而是触发,相当于你点击)