duanfu2562 2015-01-06 09:54
浏览 149
已采纳

.show()方法有时在谷歌浏览器中不起作用,而它在Firefox中完美运行

I have following array ,which consists of category and subcategory.

        $event_category = array(
        'Entertainment' => array('Music/Concerts', 'Theatre and Arts', 'Dance and Yoga', 'Night life and Parties', 'Food and Dining', 'Festivals', 'Kids Events', 'Awards', 'Others'),
        'Sports' => array('Adventure', 'Cricket', 'Cycling', 'Fitness', 'Marathon', 'Others'),
        'Exhibhitions Fairs' => array('Technology', 'Education', 'Real Estate', 'Travel, Tourism, leisure', 'Trade Fairs', 'Others'),
        'College Events' => array('College Fest', 'Alumni Meet', 'Summer Camps', 'Others'),
        'Corporate' => array('Conferences', 'Seminars', 'Others'),
        'Competitions' => array(),
        'Awards' => array(),
        'Not for profit' => array(),
        'Other' => array(),
    );

Now I am populating the above array as category and subcategory.

  <select style="color:#999;" name="category" id="category">
          <option  value="0"> Select </option>
         <?php foreach ($event_category as $key => $val) { ?>
           <option value="<?php echo $key; ?>" style="color:#585858;"><?php echo $key; ?></option>  
        <?php }
        ?>
   </select>


    <select  style="color:#999;" name="subcategory" id="subcategory">
   <option  style="color:#999;" class="axyzb" value="0"> Select </option>
      <?php
        foreach ($event_category as $key => $val) {
        foreach ($val as $value) { ?>
      <option style="display: none;color:#999;" class="<?php echo str_replace(' ', '_', $key); ?>" value="<?php echo $value ?>"><?php echo $value ?></option> 
      <?php
       }
       }
    ?>
   </select>

Initially all the subcategories are display:none except the select one . all the subcategory has class which is its main category. Now when I change the category I hide all the subcategories, take the value of selected category and show() the subcategories whose class is the value which I got from category like this

     $('#category').change(function () {
                $("#subcategory").children('option').hide();
                var cate = document.getElementById('category').value;
                cate = cate.split(' ').join('_');
                if (cate != '') {
                    $('.' + cate).show();
                    $('.axyzb').show();
                }

            })

basically I want to show subcategories according to the selected category..above code works fine for me in firefox but in chrome it does not work for two categories .when I check the console the initial display:none is removed from the html but still those subcategories are not shown on the page.

  • 写回答

1条回答 默认 最新

  • dtwxt88240 2015-01-06 09:56
    关注

    You can't show and hide <option> elements, it's not supported in all browsers, you have to actually remove them and reinsert them.

    Chrome and IE have issues with hiding options, and it's strange that it would work intermittently, as it probably shouldn't work at all.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题