按Enter键时如何触发按钮单击事件 [英] How Do I Trigger A Button Click Event When Pressing The Enter Key

查看:91
本文介绍了按Enter键时如何触发按钮单击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在开发一个Vb.net应用程序,我的aspx页面上有一个名为BtnAdd的按钮。



事件被称为btnAdd_click。



我想知道当用户按下输入时我怎么能调用事件btnAdd_click键盘上的键



我尝试过以下Javascript代码,只在页面加载时才有效,我遇到的问题是我使用异步回发来刷新当我需要在我的表中添加新行时,该表需要重新加载页面,然后脚本才能再次运行。



Hi

I am currently developing a Vb.net application and i have a button on my aspx page called BtnAdd.

The Event is called btnAdd_click.

I would like to know how would i be able to call the event btnAdd_click when the user presses the enter key on the Keyboard

I Have tried the following Javascript code which works only the when the page is loaded,problem i am having is i use an asynchronous postback to refresh just the table when i need to add new rows to my table, and then the page needs to be reloaded before the script can work again.

<script type="text/javascript" src="../jquery.min.js"></script>
    <script type="text/javascript">
      $(document).ready(function () { $("input").bind("keydown", function (event) { var keycode = (event.keyCode ? event.keyCode : (event.which ? event.which : event.charCode)); if (keycode == 13) { document.getElementById('ctl00_PageContent_btnAdd').click(); return false; } else { return true; } }); });
    </script>







请你能帮助




Please could you assit

推荐答案

(document).ready(function(){
(document).ready(function () {


(input)。bind(keydown,function(event){var keycode =(event.keyCode? event.keyCode:(event.which?event.which:event.charCode)); if(keycode == 13){document.getElementById('ctl00_PageContent_btnAdd')。click(); return false;} else {return true;} });});
< / script >
("input").bind("keydown", function (event) { var keycode = (event.keyCode ? event.keyCode : (event.which ? event.which : event.charCode)); if (keycode == 13) { document.getElementById('ctl00_PageContent_btnAdd').click(); return false; } else { return true; } }); }); </script>







请你帮忙




Please could you assit


hi
试试这个链接

http://stackoverflow.com/questions/18160342/jquery-how-to-trigger-click-event-on-pressing-enter-key [ ^ ]



http:// stackoverflow .com / questions / 17811136 / call-button-click-event-on-pressing-enter-c-sharp [ ^ ]


http://stackoverflow.com/questions/18306752/pressing-enter-return-key-doesnt-trigger-button-click-in-safari [ ^ ]



http://social.msdn.microsoft.com/Forums/en-US/70b264bf-5786-49ea-be74-837007eb1110/triggering-button-click-event- on-press-enter-key?forum = winformsdesigner [ ^ ]
hi try this links
http://stackoverflow.com/questions/18160342/jquery-how-to-trigger-click-event-on-pressing-enter-key[^]

http://stackoverflow.com/questions/17811136/call-button-click-event-on-pressing-enter-c-sharp[^]

http://stackoverflow.com/questions/18306752/pressing-enter-return-key-doesnt-trigger-button-click-in-safari[^]

http://social.msdn.microsoft.com/Forums/en-US/70b264bf-5786-49ea-be74-837007eb1110/triggering-button-click-event-on-pressing-enter-key?forum=winformsdesigner[^]


这篇关于按Enter键时如何触发按钮单击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆