如何在单击asp.net按钮时调用javascript的keydown事件 [英] How to call a keydown event for javascript when asp.net button is clicked

查看:97
本文介绍了如何在单击asp.net按钮时调用javascript的keydown事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

单击按钮时是否可以为文本框调用javascript keydown函数?

is it possible to call a javascript keydown function for a textbox when a button is clicked?

推荐答案

请参阅我对该问题的评论。



所以,让我继续这一点。而不是调用处理程序,谁知道什么,你写一些功能。从两个事件处理程序中调用此函数,或者更多,例如,一个元素的 keydown 事件处理程序,另一个将是单击按钮的事件处理程序。这样,您将在两个不同的事件处理程序中包含相同的功能,包括相同的元素或不同的元素。



顺便说一下,如果你在你的中使用this处理程序,不要忘记它们是不同的这个,不同的引用,所以一定要通过适当的参考你的功能。如果在你的函数中你也想使用this,你可以使用 yourFunction.call yourFunction.apply 来明确传递:

https:// developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call [ ^ ],

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply [ ^ ]。



-SA
Please see my comment to the question.

So, let me continue from this point. Instead of "calling a handler", which would be who knows what, you write some function. Call this function from two event handlers, or more, say, one would be a keydown event handler of one element, and another would be, say, click event handler of your button. This way, you will include identical functionality in two different event handlers, of the same element or different elements.

By the way, if you use "this" in your handlers, don't forget that they are different "this", different references, so be sure to pass appropriate reference to your function. If in your function you also want to use "this", you can use yourFunction.call or yourFunction.apply to pass it explicitly:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call[^],
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply[^].

—SA


这篇关于如何在单击asp.net按钮时调用javascript的keydown事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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