jquery选择选项

我有以下选项框:

  Miner Puffer Snipey Max Firebot 

但是,当我执行以下jquery选项onload时,文本(选定选项)不会更改为Max:

 $("#inputselection1 option[text=Max]").attr("selected","selected"); 

是什么赋予了?

谢谢!

使用.val()按选项值设置选择值:

 $("#inputselection1").val(4);​ 

如果您坚持按文字选择,请使用以下内容:

 $("#inputselection1 option").filter(function() { return $(this).text() === 'Max'; }).attr("selected", "selected"); 

如果要通过选项文本进行选择,可以使用filterfunction

 $("#inputselection1 option").filter(function() { return $(this).text() === 'Max'; }).prop("selected", true); 

小提琴

$(“#inputselection1 option [value = 4]”)。attr(“selected”,“selected”);

取自

jQuery Set选择索引