获取下拉菜单最后一个选项的值? [英] Get value of last option of a drop down?

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

问题描述

我有下拉菜单,它是动态的。如何获得下拉菜单中最后一项的值(使用jquery也是可以接受的)

I have dropdown menu..which is dynamic.. How can get value of the last item in that drop down (using jquery is also acceptable)

推荐答案

使用jQuery它非常简单:

With jQuery it's super easy:

var lastValue = $('#idOfSelect option:last-child').val();

使用简单的Javascript并不会太糟:

With plain Javascript it's not much worse:

var theSelect = document.getElementById('idOfSelect');
var lastValue = theSelect.options[theSelect.options.length - 1].value;

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

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