如何从jQuery的下拉列表中获取所选文本(而不是所选值)?
当前回答
如果要将结果作为列表,请使用:
x=[];
$("#list_id").children(':selected').each(function(){x.push($(this).text());})
其他回答
Try
dropdown.selectedOptions[0].text
函数read(){console.log(下拉列表.selectedOptions[0].text);}<select id=“下拉列表”><option value=“1”>第一个</option><option value=“2”>秒</option></选择><button onclick=“read()”>read</button>
$(函数(){alert('.val()='+$('#selectnumber').val()+'AND html()='+$('#selectnumber选项:selected').html()+'AND.text()=‘+$(‘#selectnumber选项:select').text(());});<script src=“https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js“></script><html xmlns=“http://www.w3.org/1999/xhtml"><head runat=“server”><title></title></head><body><form id=“form1”runat=“server”><div><select id=“selectnumber”><option value=“1”>一个</option><option value=“2”>两个</option><option value=“3”>三个</option><option value=“4”>四个</option></选择></div></form></body></html>
$('#id').find('option:selected').text();
以下内容对我有用:
$.trim($('#dropdownId option:selected').html())
如果要将结果作为列表,请使用:
x=[];
$("#list_id").children(':selected').each(function(){x.push($(this).text());})
推荐文章
- 错误:'types'只能在.ts文件中使用- Visual Studio Code使用@ts-check
- React-Native:应用程序未注册错误
- LoDash:从对象属性数组中获取值数组
- src和dist文件夹的作用是什么?
- jQuery UI对话框-缺少关闭图标
- 如何使用AngularJS获取url参数
- 将RGB转换为白色的RGBA
- 如何将“camelCase”转换为“Camel Case”?
- 我们可以在另一个JS文件中调用用一个JavaScript编写的函数吗?
- 如何使用JavaScript重新加载ReCaptcha ?
- jQuery。由于转义了JSON中的单引号,parseJSON抛出“无效JSON”错误
- 在JavaScript关联数组中动态创建键
- ReactJS和公共文件夹中的图像
- 在React Native中使用Fetch授权头
- 为什么我的球(物体)没有缩小/消失?