JQuery Mobile选择框没有显示选定的值?

时间:2012-11-22 05:05:14

标签: jquery jquery-mobile jquery-selectbox

我有一个名为 crop 种类的选择框。通过Ajax加载的种类选择框取决于裁剪的选择然后渲染到JQueryMobile,正确填充了值。但是所选的值没有显示。

原因是什么?

我的代码:

<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
                    }
                    ?>

1 个答案:

答案 0 :(得分:2)

你需要调用selectmenu('refresh');在包含选择菜单的元素上。

$( “#品种”)的html(数据).selectmenu( '刷新');

应该这样做。如果没有,请尝试:

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