yii chtml ::与内部的链接



我有一个chtml ::链接这样:

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>

您需要在此处使用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
    });
});

http://jsfiddle.net/z9xqm/1/

最新更新