0
var State = "State";
$("#StateOrigin option:contains(" + State + ")").attr('selected', 'selected');
在上面的行中,不支持获取大写和更低。我需要得到任何案件。如何在dropdownlist中获取包含值?
var State = "State";
$("#StateOrigin option:contains(" + State + ")").attr('selected', 'selected');
在上面的行中,不支持获取大写和更低。我需要得到任何案件。如何在dropdownlist中获取包含值?
:contains
必须准确的情况下,你可以使用filter(function)
代替
var State = "State";
$("#StateOrigin option").filter(function(){
return $(this).text().toLowerCase() === State.toLowerCase();
}).prop('selected', true);
这是假设你确实找选项的文字和选择不value
。
如果您正在寻找value
您可以在上面的代码转换为val()
text()
var State = "State";
$("#StateOrigin option").filter(function(){
return $(this).text().toLowerCase() === State.toLowerCase();
}).prop('selected', true);