2013-11-28 160 views
0

我一直在嘗試啓用或禁用多個複選框字段使用和由另一個複選框觸發的事件。Cakephp啓用/禁用多個複選框

複選框:

<?php 
    echo $this->Form->input('has_ss',array('label'=>'Los ocupantes de la vivienda ¿Cuentan con seguridad social?')); 
    echo $this->Form->input('imss',array('label'=>'IMSS','disabled'=>true)); 
    echo $this->Form->input('issste',array('label'=>'ISSSTE','disabled'=>true)); 
    echo $this->Form->input('ssy',array('label'=>'SSY','disabled'=>true)); 
    echo $this->Form->input('seguro_popular',array('label'=>'Seguro Popular','disabled'=>true)); 
    echo $this->Form->input('oportunidades',array('label'=>'Oportunidades','disabled'=>true)); 
    echo $this->Form->input('otro',array('label'=>'Otro','disabled'=>true)); 

?> 

第一個複選框suposed以觸發改變的事件,這是該操作的代碼:

$this->Js->get('#BeneficiaryHasSs')->event('change', 
    "if($('#BeneficiaryHasSs').is(':checked')) 
    { 
     alert('I'm checked'); 
    }" 
); 

警報纔來檢查代碼爲工作(這不是),也與此我需要檢查主複選框是否被選中,並啓用/禁用其他人一個接一個,我想知道是否有任何其他方式來做到這一點...或至少一些幫助在上面的代碼中找出我的錯誤。

在此先感謝!

回答

0

我知道這是Cake部分,但您可以使用jQuery輕鬆完成此操作。

$("#BeneficiaryHasSs").click(function() { 
    if ($(this).prop('checked') == true) { 
     alert("I'm checked"); 
     $(".commonclass").prop('disabled', false); 
    } else { 
     $(".commonclass").prop('disabled', true); 
    } 
}); 

只需要給所有被禁止的領域/啓用在一起類commonclass