如何从 JavaScript 调用 LinkButton OnClick 事件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12098508/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I call LinkButton OnClick Event from JavaScript?
提问by coceban.vlad
In my case a have a LinkButton on the page:
在我的情况下,页面上有一个 LinkButton:
<asp:LinkButton ID="LinkButton5" runat="server" OnClick="LinkButton5_Click">Delete</asp:LinkButton>
When a user clicks it, the choosen file is deleted. And to make it easy to use I added a HotKey JavaScript:
当用户单击它时,所选文件将被删除。为了方便使用,我添加了一个 HotKey JavaScript:
<script type="text/javascript" src="Java/Jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="Java/Jquery.hotkeys-0.7.9.js"></script>
<script type="text/javascript">
function domo() {
jQuery('#platform-details').html('<code>' + navigator.userAgent + '</code>');
jQuery(document).bind('keydown', 'esc', function (evt) { alert("ESC"); return false; });
jQuery(document).bind('keydown', 'space', function (evt) { alert("SPACE"); return false; });
jQuery(document).bind('keydown', 'del', function (evt) { alert("DEL"); return false; });
}
jQuery(document).ready(domo);
</script>
So, ones you press Delete Button on your KeyBoard JavaScript alerts you that it was clicked. :) I need ones I click Del Button LinkButton5 should be clicked. I dont realy know how I can connect the javascript call the folowing OnClick event. Please Help!
所以,当你按下键盘上的删除按钮时,JavaScript 会提醒你它被点击了。:) 我需要我点击 Del 按钮 LinkButton5 应该被点击。我真的不知道如何连接 javascript 调用以下 OnClick 事件。请帮忙!
回答by Rakesh
you can use the following code..
您可以使用以下代码..
add the code after you alert('DEL');
在 alert('DEL'); 之后添加代码
var btn = document.getElementById('<%=LinkButton5.ClientID%>');
btn.click();
回答by Venki
document.getElementById('<%=LinkButton5.ClientID%>').click();
回答by Ashirvad
try adding this line to your script file
尝试将此行添加到您的脚本文件中
jQuery(document).bind('keydown', 'del', function (evt) { alert("DEL");$('#<%=LinkButton5.ClientID%>').trigger('click'); return false; });
回答by Amiram Korach
Replace:
代替:
alert("DEL"); return false;
With
和
<%= ClientScript.GetPostbackEventReference(LinkButton5, null) %>