简体   繁体   English

更改选择列表的选定值

[英]Change the selected value of the selectlist

I am using selectmenu plugin for my select list. 我将selectmenu plugin用于我的选择列表。 I want to change the selected value of the selectlist using jquery. 我想使用jquery更改选择列表的选定值。 I tried : 我试过了 :

               $('select').val("new selected value");
               $('select').selectmenu("value", "new selected value");

But both of the above are not working. 但是以上两种都不起作用。 Help me out please? 请帮帮我吗?

The Doc says following 医生说以下

// read
$('select#speedA').selectmenu("value")
// write
$('select#speedA').selectmenu("value", "VALUE")

And this works also. 这也可以。 Check this out 看一下这个

EDIT 编辑

The problem could be, your "New Value" must not be matching from list of options you have for the select list. 问题可能是,您的“新值”必须与选择列表的选项列表不匹配。 The text should match exactly. 文字应完全匹配。

In my example, try changing this line $('select').selectmenu("value", "An Army") to 在我的示例中,尝试将此行$('select').selectmenu("value", "An Army")更改为

$('select').selectmenu("value", "An Army1") 

And see this wont work either 并且看到这也不起作用

$('select').selectmenu("value", "new selected value")应该可以,但是您必须使用选项索引而不是“新选定的值”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM