【问题标题】:jquery show hide select option blockjquery 显示隐藏选择选项块
【发布时间】:2012-03-24 00:49:22
【问题描述】:
<div class="langs">
    <div class="flag"><h3>Country</h3>
       <img id="flag" src="../media/images/flags/en.png"/>
    </div>
   <select class="select_country" name="country" id="select_country">
   <option>United States</option>
   <option>Spain</option>
   <option >France</option>
   </select>
   </div>

jquery:

    $(".langs").hover(function() {
    $("#select_country").slideToggle('500').css({"display":"block"});

    });

我不会在鼠标悬停时显示选择块,在选择国家后隐藏选择块。

【问题讨论】:

    标签: jquery select hide show option


    【解决方案1】:

    这样的?

    $(".langs").mouseenter(function() {
        $("#select_country").show(); // SHOW #select_country on mouse over
    });
    
    $(".langs").mouseleave(function() {
        $("#select_country").hide(); // HIDE #select_country on mouse out
    });
    

    您可能还想使用 .slideDown().slideUp() 代替 .show() 和 .hide()

    示例:http://jsfiddle.net/xUWK6/1/

    【讨论】:

    • 可以在 Firefox 中工作,但不能在 IE 和 google chrome 中工作!
    • 尝试改用.mouseover().mouseout()
    • 我将 select->option 更改为 ul->li 标签,现在可以正常工作了。使用 IE 和 Chrome 中的 select->option 无法正常工作(当我不选择项目时,它会消失)。
    【解决方案2】:
    //By default hide the select box
    $("#select_country").hide();
    
    //On mouseover it will show the select box
    $(".langs").mouseover(function() {
        $("#select_country").show();
    });
    
    //Once you change the selection it will hide itself
    $("#select_country").change(function(){
        $(this).hide();
    });
    

    【讨论】:

      猜你喜欢
      • 2017-04-10
      • 1970-01-01
      • 2012-12-17
      • 2014-11-23
      • 2013-08-24
      • 2014-06-20
      • 2018-04-17
      • 2015-06-27
      • 1970-01-01
      相关资源
      最近更新 更多