简体   繁体   English

如何正确使用click事件在类中调用另一个函数?

[英]How do you use the click event properly to call another function within the class?

I was confused on how to use the click event in order to call another function within the class. 我对如何使用click事件来调用类中的另一个函数感到困惑。

$.fn.imageareaselect(image)
{ 
this.click(function(){
$.fn.pinpointImage.add(image);
});
}

The selector that is passed into this function is an image. 传递给此函数的选择器是图像。 I wan't to make it so when you click the image it calls that function. 我不想这样做,所以当您单击图像时它将调用该函数。

jQuery's kinda funny about passing an HTML element when you'd expect a jQuery one. jQuery有点有趣,可以在需要jQuery元素时传递HTML元素。 try using $(this) instead of this . 尝试使用$(this)代替this

Also, jQuery functions like to take functions as params, but i'm not sure exactly what this code is trying to do now. 另外,jQuery函数喜欢将函数作为参数,但是我不确定这段代码现在到底想做什么。 The first "(image)" should probably be "= function(image)" instead. 第一个“(图像)”可能应该改为“ = function(图像)”。

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

相关问题 您如何在HTML中正确调用JS函数? - How do you properly call a JS function within HTML? 如何使用 setInterval() 在另一个 function 中定期调用单击 function? - How to use setInterval() to call a click function periodically within another function? 使用ES6类:如何从事件处理程序中调用方法? - Using an ES6 class: how do you call a method from within an event-handler? Javascript - 如何从该类中调用类中的函数? - Javascript - How do you call a function inside a class from within that class? 如何在React自定义Hook中正确调用useState? - How do you properly call useState within a React custom Hook? 如何从另一个方法中正确调用类方法 - How to properly call a class method from within another method 你如何在另一个class中调用一个module.exports = function()里面的一个function? - How do you call a function inside a module.exports = function () in another class? 我如何正确地使用“ for循环”在一个骰子功能中滚动一个(或多个)骰子? - How do I properly use a “for loop” to roll one die (or multiple) within a function of another die roll? 如何为整个 class 按钮创建点击事件? jquery - How do you make a click event for an entire class of buttons? jquery 在这种情况下,如何正确地从化简器/动作中调用函数? - How do you properly call a function from the reducer/actions in this context?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM