这感觉像是一个业余问题,但是如何在 Javascript/jQuery 中的自定义函数中接收事件?
现在我正在使用这个:
$(".button").on("click", function(event){
removeButton();
});
function removeButton() {
$(this).removeClass("specifiedClass");
}
我试图让 removeButton()
了解我希望它删除 .button
本身上的类。
我不确定如何让 removeButton()
接收该事件,但我已经尝试过:
$(".button").on("click", function(event){
removeButton(event);
});
function removeButton(event) {
$(this).removeClass("specifiedClass");
}
但它不起作用。有谁知道怎么做吗?
最佳答案
您需要将元素作为参数传递:
$(".button").on("click", function(event){
removeButton(this);
});
function removeButton(elem) {
$(elem).removeClass("specifiedClass");
}
关于javascript - 如何在 Javascript/jQuery 中获取事件变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18302040/