jQuery Mobile的没有显示在列表中正确选择的项目 [英] jQuery mobile not displaying correct selected item in list

查看:146
本文介绍了jQuery Mobile的没有显示在列表中正确选择的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个选择列表。我使用jQuery来更新所选项目。在框中显示的项目时,我改变选择的值不会更新。在下面的例子中选择a作为选定的设置。然后我使用jQuery选择的项目更改为D。它仍然显示A。但是,如果您展开列表,你可以看到,D是选择或突出显示。不知道如何解决这个问题。任何帮助将是AP preciated!

http://jsfiddle.net/9wQcs/5/

HTML:

 <选择ID =T>
  <选项>选择吲; /选项>
  <选项ID =选择A=选择了>将< /选项>
  <选项ID =B> B< /选项>
  <选项ID =C> C< /选项>
  <选项ID =D> D< /选项>
< /选择>

jQuery的:

  $(文件)。就绪(函数(){
$('#D')丙('选择','选择')。
});

谢谢,
布赖恩


解决方案

首先,在jQuery Mobile的使用。就绪()不要

选择当的选项的编程方式,您需要重新ehance的 selectme​​nu 的部件。

  $(#ID)丙(选中,真正的);
$(select_id)selectme​​nu(刷新);


  

演示


I have a select list. I am using jQuery to update the selected item. The displayed item in the box isn't updating when I change the selected value. In the following example option "a" is set as selected. Then I use jQuery to change the selected item to "d". It still shows "a". However if you expand the list you can see that "d" is selected or highlighted. Not sure how to fix the issue. Any help would be appreciated!

http://jsfiddle.net/9wQcs/5/

Html:

<select id="t">
  <option>select one</option>
  <option id="a" selected="selected">a</option>
  <option id="b">b</option>
  <option id="c">c</option>
  <option id="d">d</option>
</select>

jQuery:

$(document).ready(function () {
$('#d').prop('selected', 'selected');
});

Thanks, Brian

解决方案

First of all, refrain from using .ready() in jQuery Mobile.

When selecting an option programmatically, you need to re-ehance selectmenu widget.

$("#id").prop("selected", true);
$("select_id").selectmenu("refresh");

Demo

这篇关于jQuery Mobile的没有显示在列表中正确选择的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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