如何从jQuery的下拉列表中获取所选文本(而不是所选值)?
当前回答
Use:
('#yourdropdownid').find(':selected').text();
其他回答
如果要将结果作为列表,请使用:
x=[];
$("#list_id").children(':selected').each(function(){x.push($(this).text());})
对于正在使用SharePoint列表且不想使用长时间生成的id的用户,这将起作用:
var e = $('select[title="IntenalFieldName"] option:selected').text();
这里张贴的答案,例如,
$('#yourdropdownid option:selected').text();
对我来说没用,但这样做了:
$('#yourdropdownid').find('option:selected').text();
它可能是jQuery的旧版本。
这段代码对我有用。
$("#yourdropdownid").children("option").filter(":selected").text();
在兄弟姐妹的情况下
<a class="uibutton confirm addClient" href="javascript:void(0);">ADD Client</a>
<input type="text" placeholder="Enter client name" style="margin: 5px;float: right" class="clientsearch large" />
<select class="mychzn-select clientList">
<option value="">Select Client name....</option>
<option value="1">abc</option>
</select>
/*jQuery*/
$(this).siblings('select').children(':selected').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授权头
- 为什么我的球(物体)没有缩小/消失?