什么是“返回”?在“返回MyFunction()”中做 [英] What does the "return" do in "return MyFunction()"

查看:97
本文介绍了什么是“返回”?在“返回MyFunction()”中做的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Moz Dev Network上,它提供了一个使用onchanged的示例:

On the Moz Dev Network, it give an example of using onchanged like this:

<textbox id="find-text" onchange="return myFunction(event);"/>

上面和下面有什么区别,不使用return?

What is the difference between the above and the below which does not use "return"?

<textbox id="find-text" onchange="myFunction(event);"/>

这是一个完整的例子:

<input onchange="return checkChanged()" type="checkbox" />
<script>
    function checkChanged() {
        alert("checkChanged");
        return false;
    }
</script>

无论我是否使用返回,该值在点击后总是会改变。我认为,因为它返回false,所以它不会让用户选中该框。

Whether I use the "return" or not, the value always changes after being clicked. I would think that since it returns false, then it would not let the user check the box.

编辑:这个例子中的实际答案是Nothing。但是,这是因为onchange不可取消。其他事件,例如onclick ARE可取消,并且返回false会阻止默认操作,例如阻止点击生效(即,检查不会改变。)

The actual answer in this example is "Nothing." However, this is because onchange is not cancelable. Other events, such as onclick ARE cancelable, and returning false prevents the default action, such as preventing the click from taking effect (ie, the check would not change.)

推荐答案

这将返回 myFunction()调用的结果。在你的情况下,如果这将返回布尔值,这将改变或不是< textarea> 内容。

This will return result of your myFunction() invoking. In your case if this will return Boolean value this will change or not <textarea> content.

阅读更多关于 功能 在MDN和 onchange 元素属性。

Read more about Function's at MDN and onchange element property.

这篇关于什么是“返回”?在“返回MyFunction()”中做的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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