假设我有一个函数。我希望它在触发事件时返回一个值,比如单击按钮时。在函数中,我有 var funcStorage=this;
在按钮中,我有 onclick="funcStorage.return("something");"
。
首先,我如何让函数异步等待点击。其次,如何触发这样的返回语句?另外,我是一个非常新的用户,这是我的第一个问题。如何格式化代码?
最佳答案
在你的按钮中:
onclick="return MyFunction('something')"
你的功能:
function MyFunction(arg)
{
//do stuff
return true; //return false if you don't want the button action to happen
}
关于JavaScript 在事件后返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8937173/