如何从jQuery的下拉列表中获取所选文本(而不是所选值)?
当前回答
这段代码对我有用。
$("#yourdropdownid").children("option").filter(":selected").text();
其他回答
这段代码对我有用。
$("#yourdropdownid").children("option").filter(":selected").text();
$("#dropdown").find(":selected").text();
$("#dropdown :selected").text();
$(“#下拉选项:selected”).text();
$("#dropdown").children(":selected").text();
$("select[id=yourDropdownid] option:selected").text()
这很好
只需尝试以下代码。
var text= $('#yourslectbox').find(":selected").text();
它返回所选选项的文本。
$(“#DropDownID”).val()将给出选定的索引值。
推荐文章
- 在React Native中使用Fetch授权头
- 为什么我的球(物体)没有缩小/消失?
- 如何使用jQuery检测页面的滚动位置
- if(key in object)或者if(object. hasownproperty (key)
- 一元加/数字(x)和parseFloat(x)之间的区别是什么?
- angularjs中的compile函数和link函数有什么区别
- 删除绑定中添加的事件监听器
- 如何在JSON中使用杰克逊更改字段名
- 很好的初学者教程socket.io?
- HtmlSpecialChars在JavaScript中等价于什么?
- React: 'Redirect'没有从' React -router-dom'中导出
- 如何在React中使用钩子强制组件重新渲染?
- 我如何使用Jest模拟JavaScript的“窗口”对象?
- 我如何等待一个承诺完成之前返回一个函数的变量?
- 在JavaScript中根据键值查找和删除数组中的对象