Javascript .trigger()a.on()

Javascript .trigger()a.on(),javascript,jquery,Javascript,Jquery,vote\u now应被触发并弹出值,但出现问题。这是什么 $此声明不正确。在第6行使用$(this) 您忘记了var$this=$(this),并且额外的参数将在事件对象之后传递 var $forms = $('form.vote'); $forms.submit(function(){ return false; }); $('.votebtn').on('click',function(){ $this.closest('form').trigger('vote_now'

vote\u now
应被触发并弹出值,但出现问题。这是什么


$此
声明不正确。在第6行使用
$(this)


您忘记了
var$this=$(this),并且额外的参数将在事件对象之后传递

var $forms = $('form.vote');
$forms.submit(function(){
    return false;
});
$('.votebtn').on('click',function(){
    $this.closest('form').trigger('vote_now', [$(this).val()]);
});

$forms.on('vote_now',function(value){
    alert(value);
});

您能在中重新创建此问题吗?这就引出了一个问题,即如果他在数组中包装参数,他可能希望访问元素(即:alert(value[0]),您能检查一下这里的错误吗?我正在给按钮添加一个类@user1099531:你的意思是因为没有添加
禁用的
类?这是因为您试图将回调函数传递给
addClass
,而该函数不接受回调。(如果您加载了jQueryUI,可能会发生这种情况。)
var $forms = $('form.vote');
$forms.submit(function(){
    return false;
});
$('.votebtn').on('click',function(){
    var $this = $(this);  // declare variable
    $this.closest('form').trigger('vote_now', [$(this).val()]);
});
                                   // second argument, not first.
$forms.on('vote_now',function( e, value ){
    alert(value);
});