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 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置