在我的网站上,我使用CHtml::ajaxLink,它对我来说很好,可以删除我需要的内容但我想用这个选项显示javascript确认消息,任何人都能帮我吗
<?php
echo CHtml::ajaxLink('X',Yii::app()->createUrl('admin/deleteimg'),
array(
'type'=>'POST',
'data'=> 'js:{"data":'.$img->id.'}',
'success'=>'js:function(string){ document.getElementById("'.$img->id.'").remove(); }'
),array('class'=>'btn btn-danger small-btn'));
?>
您可以在htmlOptions
数组中添加confirm。看看:
<?php
echo CHtml::ajaxLink('X',Yii::app()->createUrl('admin/deleteimg'),
array(
'type'=>'POST',
'data'=> 'js:{"data":'.$img->id.'}',
'success'=>'js:function(string){ document.getElementById("'.$img->id.'").remove(); }'
),array(
'class'=>'btn btn-danger small-btn',
'confirm'=>'Are you sure?' //Confirmation
));
?>
将其作为另一行(函数)添加到成功函数中。这应该正常工作:
echo CHtml::ajaxLink('X',Yii::app()->createUrl('admin/deleteimg'), array(
'type'=>'POST',
'data'=> 'js:{"data":'.$img->id.'}',
'success'=>'js:function(string){
document.getElementById("'.$img->id.'").remove();
alert("Image deleted!"); }' // this is the line I added
),
array(
'class'=>'btn btn-danger small-btn'
));