2012-11-22 40 views
1

我有一个名为作物各种 .The 各种选择框通过Ajax加载选择框取决于作物的选择,然后呈现给JQueryMobile,填充correctly.but所选值的值不显示。JQuery Mobile选择框不显示选定的值?

原因是什么?

我的代码:

<script> 
      $(document).ready(function() { 
       $("#crop").change(function(){ 
        $.ajax({ 
         type:'GET', 
         url :'variety.php', 
         dataType:"json", 
         //data:"fname=me", 
         data: ({crop: $('#crop').val()}), 
         success : function(data){ 
          //      alert(data); 
          $("#variety").html(data);        
         }, 
         error : function(data){ 
          //      alert("Error"+data); 
         } 
        }); 

       }); 
      }); 
     </script> 
<div data-role="fieldcontain"> 
          <label for="crop" class="select">Crop :</label> 
          <select name="crop" id="crop" data-native-menu="false"><option selected>Choose an option</option> 
           <?php 
           while ($res = mysql_fetch_assoc($tests)) { 
            $dropdown .= "\r\n<option value='{$res['id']}'>{$res['crop_name']}</option>"; 
           } 
           echo $dropdown; 
           //} 
           ?> 
          </select> 
         </div> 
         <div data-role="fieldcontain"> 
          <label for="variety" class="select">Variety :</label> 
          <select name="variety" id="variety" data-placeholder="true"> 
          </select> 
         </div> 
<?php 
        } 
        ?> 

回答

2

你需要调用selectmenu( '刷新');在包含选择菜单的元素上。 ('#variety“)。html(data).selectmenu('refresh');

应该这样做。如果不是,请尝试:

$(“#variety”)。html(data).selectmenu('refresh',true);

+0

其工作......谢谢@Aaron – Jishin

+0

很高兴听到它。几周前,几乎同样的问题让我感到沮丧,除了单选按钮。 – Aaron

+0

+1节省我的时间。 – neeraj