更改选择菜单Jquery Mobile的选定值 [英] Changing the Selected value of Select Menu Jquery Mobile

查看:113
本文介绍了更改选择菜单Jquery Mobile的选定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个表单,并将用户选择的值存储在数据库中. 但是现在,如果用户要编辑他的表单,我需要使用以前的值重新加载表单.我正在使用JQUERY MOBILE

I have created a form and have stored the values selected by the user in a database. But now if the user wants to edit his form, i need to reload the form with the previous values.I am using JQUERY MOBILE

我从数据库中检索了他以前的值,但是现在我在选择菜单中加载值时遇到问题.有人可以帮我吗?

I retrieved his previous values from the database but now i am having a problem with loading the values in a select Menu.Can anyone help me ?

我使用了以下代码:-

     var nameVar = (dataset.item(id)['name']);  // Getting the name from the database
     $('#StateName').val(nameVar);                   // StateName is the id  
     $('#StateName').selectmenu('refresh', true);    // Refreshing the Select Menu

但是即使执行了上面的代码,选择菜单中也没有反映出任何内容 代码有什么错误吗?还是我缺少什么?

But even after the execution of the above code nothing is reflected in the select Menu Is something Wrong in Code or am i missing something ?

推荐答案

您需要附加以下选项来代替值:

Instead of value you need to append the option:

var nameVar = (dataset.item(id)['name']);
$('#StateName').append('<option value="'+nameVar+'" selected="selected">'+nameVar+'</option>');                     
$('#StateName').selectmenu('refresh', true);  

或者如果您已经具有选择选项"并且只需要选择该选项,请尝试以下操作:

Or if you have the Select Options already and just need to select the option, try this:

var nameVar = (dataset.item(id)['name']);
$('#StateName option[value='+nameVar+']').attr('selected', 'selected');
$('#StateName').selectmenu('refresh', true);

有关jQM 1.0的选择"菜单的更多信息,在这里:

More on Select Menu for jQM 1.0 here:

这篇关于更改选择菜单Jquery Mobile的选定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆