使用 jquery 按值更改/修改下拉列表文本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1974256/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 12:30:20 来源:igfitidea点击:
change/modify the dropdownlist text by value using jquery
提问by Prasad
i have dropdownlist with the values:
我有带有值的下拉列表:
<select id="myddl" name="myddl">
<option value="1">One</option>
<option value="2">Twooo</option>
<option value="3">Three</option>
</select>
I need to change the text Twooo
to Two
using the value of the dropdownlist option(2)
. How can i do it in jquery?
我需要将文本更改Twooo
为Two
使用下拉列表选项的值(2)
。我如何在 jquery 中做到这一点?
回答by Kobi
$('#myddl option[value=2]').text('Two');
回答by vapcguy
var myDLLField = $('select[id="myddl"]');
myDLLField.find('option[value="2"]').text("Two");
or, in one line...
或者,在一行...
$('select[id="myddl"]').find('option[value="2"]').text("Two");