jQuery根据下拉列表显示内容 [英] jQuery show content based on dropdown

查看:85
本文介绍了jQuery根据下拉列表显示内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望根据下拉值显示内容.因此2005 select将仅显示日期为2005等的内容.

I wish to show content based on dropdown value. So 2005 select will only show content with date of 2005 etc.

HTML:

    <select id="year" name="Year"> 
        <option value="#" selected="selected">Year...</option> 
        <option value="#">2007</option> 
        <option value="#">2006</option> 
        <option value="#">2005</option> 
    </select> 

-

<li class="pr">
   <a class="image" href="image.jpg" width="50" height="50" /></a>
   <span class="date">2006</span>
</li>

<li class="pr">
   <a class="image" href="image.jpg" width="50" height="50" /></a>
   <span class="date">2007</span>
</li>

看看这个: jQuery下拉菜单根据值隐藏显示div

但是似乎过分杀伤力了?

but seems overkill?

推荐答案

$('select#year').change(function(){

    theVal = $(this).children(':selected').text();
    $('span.date').each(function(){

        if($(this).text()==theVal){
            $('li.pr').hide();
            $(this).parent().show();
        }
    });
});

抱歉,这应该与您拥有的HTML一起使用,旧的是基于价值的.

Sorry, this one should work with the HTML you have, old one was based of value.

这篇关于jQuery根据下拉列表显示内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆