获取选中的下拉选项值jquery [英] get seleceted dropdown option value jquery

查看:114
本文介绍了获取选中的下拉选项值jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个下拉菜单(分别是月份和年份)和一个按钮.当用户单击按钮时,我要获取选定的月份值和年份值,并将它们作为查询字符串传递给这样的URL:https://mysite.com/events.aspx?my=may2012.

I have two dropdowns -- for the month and year -- and a button. When the user clicks the button, I want to grab the selected month value and year value and pass them as query string to a URL like this: https://mysite.com/events.aspx?my=may2012.

如何使用jQuery或Javascript获取这些值?

How do I grab those values using jQuery or Javascript?

<div id="datepicker"></div>
<div class="calendForm">
    <span class="inpMonth">
        <select>
            <option selected="selected">September</option>
        <option>August</option>
        <option>July</option>
        <option>June</option>
        <option>May</option>
        <option>April</option>
        <option>March</option>
        <option>February</option>
        <option>January</option>
        <option>December</option>
        <option>November</option>
        <option>October</option>
        </select>
    </span>
    <span class="inpYear">
        <select>
            <option selected="selected">2012</option>
            <option>2013</option>
            <option>2014</option>
        <option>2015</option>
        </select>
    </span>
    <a href="#" type="submit" class="btnBlue"><span>GO</span></a>
</div><br />

推荐答案

T.Stone的答案有误.选择器应有一个点. 除此之外-很好的答案!

There is a mistake in T. Stone's answer. the selector should have a dot. Other than that - great answer!

看看我的小提琴

<script>
$(function(){$(".btnBlue").click(function(){
    window.location = "https://mysite.com/events.aspx?my=" + $(".inpMonth select").val().toLowerCase() + $(".inpYear select").val();
})})
</script>

这篇关于获取选中的下拉选项值jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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