doutan3040 2014-05-15 06:41
浏览 86

选中主复选框时如何使复选框可见?

good morning guys, I have 3 checkboxes created in php. one that i want to use as a controller

<p>
    <?php  $creates = array('name'=> 'single_obs_value','class' => 'singleobsyes','value'=> '1','style'=>' float: left; margin-right: 2px;'); ?>
    <?=form_label('Single Observation : ');?>
    <?=form_checkbox($creates);?>
    <br>
</p>

And the other two are brought in from a database array variable.

<p>
    <?php   foreach($obsnames as $cp){  ?>
        <?php  $create = array('name'=> 'cms_permissions[]','class' => 'singleobs','value'=> $cp->id,'style'=>' float: left; margin-right: 10px;'); ?>
        <span style="width:200px; float:left">
            <?=form_checkbox($create ).' '.form_label($cp->field_name);?>
        </span>
    <?php }  ?>
</p>

How do i first make the two brought in by the database invisible when the page loads. Then when the controller checkbox is ticked make the two checkboxes visible again. If possible with a jquery function that uses the class of the controller checkbox as such.

$('#singleobsyes').change(function(){

Rather than

$('input[type="checkbox"']

As i use other checkboxes on the page and i believe that may cause some conflict.

  • 写回答

4条回答 默认 最新

  • doumi4974 2014-05-15 06:44
    关注

    try this

    $(document).ready(function(){
      $('input[type="checkbox"]').not('.singleobsyes').hide();// hide all checkboxes other than controller
    
      $('.singleobsyes').change(function(){
    
        if($(this).is(':checked') 
            $('input[type="checkbox"]').not('.singleobsyes').show();    
        else
           $('input[type="checkbox"]').not('.singleobsyes').hide();
      });
    
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?