【发布时间】:2018-10-28 05:19:24
【问题描述】:
我很困惑,用谷歌搜索了很多,但没有找到答案。无论我尝试什么,以下代码都会导致: Uncaught TypeError: $(...).editRule is not a function。
functionName(){
[...]
$(`#index`).unbind().click(() => {
$(`#index`).editRule(rule);
});
}
editRule (rule) {
// do sth
}
参考确实有效。其他预定义函数,如 .remove() 行为正确。我尝试了很多(函数或静态,无参数,其他函数等),但错误仍然存在,我对点击事件不是很有经验。有人知道问题出在哪里吗?
【问题讨论】:
-
为什么在选择器中使用反引号
`而不是引号?$(`#ruleIndex${rule.index}-edit` -
你在引用什么 api 让你知道
editRule是一个 jQuery 方法? -
@j08691 这些是 ES6 template strings。
-
@j08691 他正在使用模板文字来构建选择器,不是吗?
-
@Taplar 这是一个自写的方法
标签: javascript jquery events click typeerror