jQuery在更改时获得所选的下拉值 [英] jQuery get the selected dropdown value on change

查看:73
本文介绍了jQuery在更改时获得所选的下拉值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取更改下拉列表的值(然后在第二个下拉列表中更改值)。

I'm trying to get the value of a dropdown on change (and then change the values in a second dropdown).

编辑:感谢所有回复,我已更新添加()但代码没有返回任何内容,不是null或未定义只是一个空白警报窗口

Thanks for all the replies, i've updated to add the () but the code is returning nothing, not null or undefined just a blank alert window

但是当我提醒它attr(值)未定义。

However when I alert it out the attr(value) is undefined.

关于我缺少的任何想法?

Any ideas on what i'm missing?

这是我的代码:

<script type="text/javascript">
            $(document).ready(function() {

                var roomID = "0"
                $('.dropone').load('ajaxdropdown.aspx');
                $('.droptwo').load('ajaxdropdown.aspx?drpType=room&roomid=' + roomID);

                $('.dropone').change(function() {
                var ts = new Date().getTime();
                alert($(this).val)

                    $(".droptwo").empty();
                    $(".droptwo").load("ajaxdropdown.aspx?drpType=room&roomid=" + $(this).attr("value") + "&ts=" + ts);
                });

            });        
        </script>


推荐答案

val 是一种方法,而不是财产。

val is a method, not a property.

使用它像 val()

如果你在很多地方使用它,我会指定它到一个局部变量并在之后使用它。

If you are using it many places, i would assign it to a local variable and use it thereafter.

你也可以使用 $。now() 用于获取唯一时间戳的函数。它等于DategetTime();

Also you can use the $.now() function to get the unique time stamp. It is equal to DategetTime();

$('.dropone').change(function() {    
    var item=$(this);
    alert(item.val())
    $(".droptwo").empty();
    $(".droptwo").load("ajaxdropdown.aspx?drpType=room
                        &roomid=" +item.attr("value") + "&ts=" + $.now());
});

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

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