需要帮助来解决这个问题!
使用Cakephp,我做的列表显示名称(一些文本),复选框和文本框。我需要的是当检查复选框时,应启用t extbox ,否则应禁用它。我试过了。但它没有像我想的那样工作。
这是代码及其jquery。
<tbody>
<?php $count = 0; ?>
<?php foreach ($get_resources['learnings'] as $learnings): ?>
<tr><td>
<?php $control_id = $this->SDNTextUtils->cleanCssIdentifier($learnings['name']); ?>
<div class="switch">
<?= $this->Form->label($control_id, __($learnings['name'])); ?></div></td>
<td>
<div class="switch">
<?= $this->Form->checkbox("lrng_permission[$count][permission]", ['class' => 'cmn-toggle cmn-toggle-round', 'id' => $control_id, 'name'=>'idd']); ?>
<?= $this->Form->label($learnings['name'], ''); ?>
<?= $this->Form->hidden("lrng_permission[$count][resource_name]", ['value' => $learnings['name']]); ?>
<?= $this->Form->hidden("lrng_permission[$count][resource_type]", ['value' => 'Learning']); ?></td>
<td> <?= $this->Form->number('',['label'=>false,'id'=>'check1','disabled' => 'disabled']); ?>
</td></tr>
</div>
<?php $count ++; ?>
<?php endforeach; ?>
</tbody>
//这是JQuery
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">
$('#idd').'change',function(){
var checked=$('#idd').is(':checked');
if(checked==true)
{
$('#check1').attr('disabled',false);
} else {
$('#check1').attr('disabled',true);
}
});
</script>
答案 0 :(得分:0)
使用三元运算符在复选框更改
上切换禁用状态
$('[name=idd]').on('change', function() {
console.log(this.checked);
$('#check1').prop('disabled', this.checked);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="checkbox" name="idd">
<textarea id="check1">textarea</textarea>