简体   繁体   English

JQuery Mobile 选择框不显示选定值?

[英]JQuery Mobile select box not displaying selected value?

I have a select box called crop and variety .The variety select box loaded via Ajax depends on the selection of crop and then rendered to JQueryMobile, the value populated correctly.but the selected value not displaying.我有一个名为作物各种.The各种选择框通过Ajax加载取决于作物的选择,然后呈现给JQueryMobile选择框,填充correctly.but所选值不显示所述值。

What could the reason?可能是什么原因?

my code:我的代码:

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

You need to call selectmenu('refresh');您需要调用 selectmenu('refresh'); on the element that contains the select menu.在包含选择菜单的元素上。

$("#variety").html(data).selectmenu('refresh'); $("#variety").html(data).selectmenu('refresh');

Should do it.应该做。 If not, try:如果没有,请尝试:

$("#variety").html(data).selectmenu('refresh', true); $("#variety").html(data).selectmenu('refresh', true);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM