javascript 在 jquery mobile 1.3.1 中,如何在选择菜单中设置选定值?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16953680/
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-10-27 06:35:18  来源:igfitidea点击:

In jquery mobile 1.3.1 how do you set selected value in a selectmenu?

javascriptjqueryjquery-mobilecordova

提问by Seth

I have tried numerous things. Nothing seems to work.

我尝试了很多事情。似乎没有任何效果。

for example:

例如:

$('#select').val(myval).selectmenu('refresh');
$('#select').val(myval).attr('selected', 'selected');
$('#select').val(myval).prop('selected',true);

回答by thefrontender

$('#select').val(myval).selectmenu('refresh');

Just make sure myvalactually matches a value in your options: <option value="myval">My value</option>

只需确保myval实际匹配选项中的值:<option value="myval">My value</option>

http://jquerymobile.com/demos/1.0a4.1/docs/forms/forms-selects.html

http://jquerymobile.com/demos/1.0a4.1/docs/forms/forms-selects.html