0
我必須將表與HABTM相關聯,並且它會完美地顯示覆選框。代碼行是這樣的:向cakephp(HABTM)中的所有複選框添加一個類
<?php echo $this->Form->input('Item.ItemCharacteristic',array('id'=>'item_characteristic','label' =>false,'type'=>'select','multiple'=>'checkbox','options' => $itemCharacteristics,'selected' => $this->Html->value('ItemCharacteristic.ItemCharacteristic')));
?>
它顯示是這樣的:
<div class="input select"><input type="hidden" name="data[Item][ItemCharacteristic]" value="" id="item_characteristic"/>
<div class="checkbox"><input type="checkbox" name="data[Item][ItemCharacteristic][]" value="8" id="item_characteristic8" /><label for="item_characteristic8">We-Fii</label></div>
<div class="checkbox"><input type="checkbox" name="data[Item][ItemCharacteristic][]" value="9" id="item_characteristic9" /><label for="item_characteristic9">Test1</label></div>
<div class="checkbox"><input type="checkbox" name="data[Item][ItemCharacteristic][]" value="10" id="item_characteristic10" /><label for="item_characteristic10">Setting</label></div>
<div class="checkbox"><input type="checkbox" name="data[Item][ItemCharacteristic][]" value="11" id="item_characteristic11" /><label for="item_characteristic11">Test4</label></div>
<div class="checkbox"><input type="checkbox" name="data[Item][ItemCharacteristic][]" value="13" id="item_characteristic13" /><label for="item_characteristic13">Solari</label></div>
<div class="checkbox"><input type="checkbox" name="data[Item][ItemCharacteristic][]" value="15" id="item_characteristic15" /><label for="item_characteristic15">Panorama</label></div>
<div class="checkbox"><input type="checkbox" name="data[Item][ItemCharacteristic][]" value="17" id="item_characteristic17" /><label for="item_characteristic17">BlusBrothers</label></div>
</div>
,所以我想要的是iput元素中添加類是這樣的:
<div class="checkbox"><input type="checkbox" name="data[Item][ItemCharacteristic][]" value="8" id="item_characteristic8" class="element" /><label for="item_characteristic8">We-Fii</label></div>
所以只是爲它添加class =「element」..
任何ide?
感謝名單@MoyedAnsari的幫助。但我設法解決它,我需要clas抓住每個複選框,看看是否至少有一個被選中,所以我把 '之前'=>「
很好。我很高興它的工作 –