简体   繁体   English

如何触发父母的功能?

[英]How to trigger parent's function?

I have this code: 我有以下代码:

function someFunction () {
  alert('fired!')
}
var options = [
  {selector: 'footer', offset: 50, callback: 'someFunction()' },
];
Materialize.scrollFire(options);

I'm getting an error Uncaught ReferenceError: someFunction is not defined 我收到一个错误Uncaught ReferenceError: someFunction is not defined

I do understand why it happens, but i can't get, how should i trigger someFunction anyway? 我确实知道为什么会发生这种情况,但我还是不明白,无论如何我应该如何触发someFunction?

ps. PS。 if i change 'someFunction()' to alert('fired!') , alert happens. 如果我将'someFunction()'更改为alert('fired!')'someFunction()'发生警报。

Just change it to a reference to the function: 只需将其更改为对函数的引用即可:

var options = [
  {
    ...
    callback: someFunction
];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何仅在父div而不是子div中触发功能 - How to trigger function only in parent div, not child Vue.js $ emit没有在回调时触发父函数 - Vuejs $emit didn't trigger parent's function on callback 从其父级 [angularJS] 触发子指令中的函数 - Trigger a function in a child directive from it's parent [angularJS] 如何通过其父级触发子级 object 上的 hover 事件? - How to trigger hover event on child's object via its parent? 如何强制jQuery的触发函数来触发forloop中的所有事件? - How to force jquery's trigger function to trigger all events in forloop? 如何使iframe中的按钮触发父窗口中特定对象上的功能? - How to make a button in an iframe trigger a function on a specific object in the parent window? 如何在父级上使用ng-show进行指令以在show上触发函数 - how to make directive with ng-show on the parent to trigger a function on show 如何从 angular 中的父组件触发子组件的 function? - How to trigger a function of child component from parent in angular? 如何通过函数的参数在javascript函数内触发javascript函数? - How to trigger javascript function, inside a javascript function, by function's argument? 如何从子窗口调用父的父javascript函数 - How to call parent's parent javascript function from child window
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM