如何使用多个事件调用相同的代码? [英] How to invoke same code using multiple events?

查看:42
本文介绍了如何使用多个事件调用相同的代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码..

$("#input_name").blur(function(){
  //more code
});

它工作正常,但现在我需要点击上面的模糊功能调用相同的功能一个按钮也是。基本上,我想保持模糊,并添加onclick。任何想法我该怎么做?
谢谢

It works fine, but now I need to invoke the same functionality as in the blur function above by clicking a button as well. Basically, I want to keep the blur as is, and add the onclick. Any ideas how do I do that? Thanks

推荐答案

将您的函数定义更改为不内联,然后重复使用。

Change your function definition to not be inline and then reuse it.

function eventFunction(){
    //more code
}

$('#input_name').blur(eventFunction);
$('#button_name').click(eventFunction);

这篇关于如何使用多个事件调用相同的代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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