[英]Yii ajaxbutton : How to get $(this) in success callback function?
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'));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.