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 回答