我有一个像这样的Chtml :: link:
echo CHtml::link('DESACTIVAR',array ('/ZfIncidencias/estado', 'id'=>$data->incidencia_id),array("class"=>"desactivar"));
这执行动作,但我需要的是:
$id_on = $data->incidencia_id;
$content_on = '<div class="onoffswitch">
<input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="'.$id_on.'" checked />
<label class="onoffswitch-label" for="'.$id_on.'">
<div class="onoffswitch-inner"></div>
<div class="onoffswitch-switch"></div>
</label>
</div> ';
echo CHtml::link($content_on,array('/ZfIncidencias/estado', 'id'=>$data->incidencia_id));
当我点击动作时没有执行。
有办法强迫它执行吗?
解决方案:
$id_off = $data->incidencia_id;?>
<div class="onoffswitch">
<input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="<?php echo $id_off;?>" unchecked onClick="javascript:location.href = '<?php echo Yii::app()->baseUrl.'/ZfIncidencias/estado/'.$data->incidencia_id;?>'"; />
<label class="onoffswitch-label" for="<?php echo $id_off;?>">
<div class="onoffswitch-inner"></div>
<div class="onoffswitch-switch"></div>
</label>
</div>
答案 0 :(得分:0)
您需要在此处使用Ajax调用。如果您不想再次重新加载页面,则可以使用Jquery.post();
检查JSFiddle并根据您在函数中的需要修改类。
$(document).on("click",".onoffswitch-checkbox", function(){
var id = $(this).attr('id');
$.post('/ZfIncidencias/estado/'+id, "", function(data){
//Change the class here
});
});