在JQUERY中单击事件后返回结果 [英] get returned result after click event in JQUERY

查看:66
本文介绍了在JQUERY中单击事件后返回结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个返回值的函数,我在点击事件后执行了该函数,例如

I have a function that return value and i executed the function after click event for example

$("some_div").click( my_function());

答案是如何获得函数的返回值。

The answer is how to get the returned value of the function.

我无法使用

var something = $("some_div").click( my_function());






感谢每一位提出问题的人。我得到了答案。


Thanks to every one who contribute the the question.I've got my answer.

推荐答案

你必须将函数传递给点击,而不是返回值。在事件处理程序中,您可以调用您的函数并按您认为合适的方式处理返回值:

You have to pass a function to click, not its return value. In the event handler you can call your function and deal with the return value as you see fit:

$("some_div").click(function() {
    var result = my_function();
    // do whatever you want with `result`
});

事件处理程序不会立即调用,但会在稍后(单击元素时)调用。因此, .click 返回一个值是没有意义的。

The event handler is not called immediately, but some time later (when the element is clicked). Therefore it does not make sense for .click to return a value.

这篇关于在JQUERY中单击事件后返回结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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