日期:2014-05-17 浏览次数:20393 次
<script type="text/javascript" src="../jQuery/jquery-1.7.2.min.js"></script> <script type="text/javascript"> $(document).ready(function(){}); function file1_Upload_Change(){ $('#btnUpload').click(); } </script>
<img id="showFace" src="../facetmp/noPhoto.jpg" runat="server" style="width: 84px; height: 107px" /><br /> <input type="file" id="file1_Upload" runat="server" onchange="javascript:file1_Upload_Change();" style="display: none" /><br /> <input type="button" id="btnUpLoad1" value="上传" onclick="javascript:document.getElementById('file1_Upload').click();" /><br /> <asp:Button ID="btnUpload" runat="server" Text="上传" style="display: none" OnClick="btnUpload_Click" /><br /> <div id="showMsg" runat="server"></div>
//取得服务器端控件的ClientID,搜索一下“ClientID” document.getElementById("<%= btnUpload.ClientID %>"); $('#<%= btnUpload.ClientID %>'); //服务器端控件的客户端click事件,搜索一下“OnClientClick” <asp:Button ID="btnUpload" runat="server" Text="上传" OnClientClick="alert('client click.');return false;" /> //jquery触发事件,包括自定义事件和浏览器默认事件,搜索一下“jquery trigger” $('#btnUpLoad1').trigger("click"); //只触发自定义动作,比如使用$('#btnUpload').click(fn);而不是<input type="button" onclick="..." />绑定了click $('#btnUpLoad1').triggerHandler("click");;
------解决方案--------------------
服务器控件调用JS 是用OnClientClick 而不是onclick
例如:
<asp:Button OnClientClick="" runat="server" />
------解决方案--------------------
document.getElementById("<%=btnUpload.ClientID%>").click()
or onclientClick="javascript:函数名称"