CHtml::ajaxButton('vote',Yii::app()->createUrl('land/Ajax'),
array(
'type'=>'POST',
'data'=> 'js:{"id": '.$post->id.'}',
'success'=>'js:function(e){
console.log($(this)); // I want to control this button's silblings
$("input.ajaxsubmit").prop("disabled", true);
}',
'error'=>'js:function(e){ console.log(e); }',
),
array('class'=>'btn btn-large ajaxsubmit'));
我无法在成功函数中获取按钮本身,因为这指向 xhr 对象。如何将按钮传递给成功功能?CHtml::ajaxButton 没有其他选择。
在
成功事件中,即使使用普通按钮而不是 yii ajaxButton,您也无法访问按钮本身。我认为此问题的一种解决方法是为按钮分配一个 id,然后使用其 id 访问按钮的同级:
CHtml::ajaxButton('vote',Yii::app()->createUrl('land/Ajax'),
array(
'type'=>'POST',
'data'=> 'js:{"id": '.$post->id.'}',
'success'=>'js:function(e){
//You can access to button with $("#voteButton")
}',
'error'=>'js:function(e){ console.log(e); }',
),
array('class'=>'btn btn-large ajaxsubmit', 'id'=>'voteButton'));