Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在jQuery中从dropdownlist获取值_Javascript_Jquery_Html_Events_Drop Down Menu - Fatal编程技术网

Javascript 如何在jQuery中从dropdownlist获取值

Javascript 如何在jQuery中从dropdownlist获取值,javascript,jquery,html,events,drop-down-menu,Javascript,Jquery,Html,Events,Drop Down Menu,我在我的网页上有一个下拉列表,我可以从中选择的选项中获取值 像 我需要它 如何在选择时获得“我需要它”的值 我不是说属性“值”,我需要一个值,它填充dropdownlist的选项标签 一切都在等着你试试看 $("#selme").change(function(){ $(this).find("option:selected").text(); }); 请看这是我刚刚为您制作的一个JSFIDLE 基本上,它实际上只是$(“#selme”).val() 试试这个 $('#selme选

我在我的网页上有一个下拉列表,我可以从中选择的选项中获取值


我需要它
如何在选择时获得“我需要它”的值

我不是说属性“值”,我需要一个值,它填充dropdownlist的选项标签

一切都在等着你

试试看

$("#selme").change(function(){
    $(this).find("option:selected").text();
});

请看

这是我刚刚为您制作的一个JSFIDLE

基本上,它实际上只是$(“#selme”).val()

试试这个

$('#selme选项:选中')。text()

查看-->

用于获取文本

$("#selme").change(function(){
 $(this[this.selectedIndex]).text();
});
获取价值

$("#selme").change(function(){
 $(this[this.selectedIndex]).val();
});

阿克,我正要写一个类似的答案,但你抢先给了我:)太复杂了,$('selme').val();太漂亮了!这将无法获取上述上下文中的正确结果。这将生成值而不是文本。@Andreyco.val()不会获取“我需要它”字符串
$("#selme").change(function(){
 $(this[this.selectedIndex]).text();
});
$("#selme").change(function(){
 $(this[this.selectedIndex]).val();
});