0

次のような 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>
4

1 に答える 1

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
    });
});

http://jsfiddle.net/z9xQM/1/

于 2014-03-07T16:00:08.427 に答える