JQuery:如何知道值的选择名称?

Tom*_*Tom 1 javascript jquery select

我需要在其值已知时获取select(#Dropdown)的名称,但似乎无法使语法正确.这是一个例子:

$(document).ready(function()
{
   var countrycode = '55';
   var name = $("#Dropdown[value=countrycode]").text();  // fails here
   if(name == 'Germany')
   {..... etc
Run Code Online (Sandbox Code Playgroud)

当我能够使用"this"时,我可以在不同的上下文中按照以下方式工作:

var name = $(this[value=countrycode]).text();
Run Code Online (Sandbox Code Playgroud)

...但是在第一个例子中没有.

任何人?谢谢.

mun*_*nch 5

您需要在select中查找选项值.

var countrycode = '55';
var name = $("#Dropdown option[value="+countrycode+"]").text();
Run Code Online (Sandbox Code Playgroud)