Jquery Mobile-使用Ajax选择显示值resfresh

Jquery Mobile - select displayed value resfresh with Ajax

本文关键字:显示 resfresh 选择 Ajax Mobile- 使用 Jquery      更新时间:2023-09-26

我花了几个小时试图解决这个问题,但没有成功。

我的页面中有一个选择和一个查询,旨在更新所选值和显示的值。

显示的值永远不会更新。当我单击选择时,该值是正确的。

这是我的代码:

<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js">
<fieldset class="ui-field-contain">
     <label for="device1">device1 Roma home</label>
     <select name="device1" id="device1"  >
          <option value="Roma">Roma</option>
          <option value="Paris">Paris</option>
          <option value="London">London</option>
          <option value="Madrid">Madrid</option>
          <option value="Berlin">Berlin</option>
     </select>
</fieldset>
<script type="text/javascript">
   $(document).ready(function(){
   some code here...
   PUBNUB_demo.subscribe({
         channel: 'datavenueGeolocator',
         message: function(m){
          $( "#device1" ).val(m['device1']);  
         }
     });
   });

</script>

m['device1']包含例如"Paris"

我尝试了很多东西。。。菜单选择,刷新。。。没有成功。

提前感谢您的帮助。Aure

设置新值后,您需要告诉jQM刷新selectmenu窗口小部件:

$( "#device1" ).val((m['device1']).selectmenu("refresh"); 

http://api.jquerymobile.com/selectmenu/#method-刷新