2012-11-22 41 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