0

我有两个选择框,称为crop 和variety。通过Ajax 加载的品种选择框取决于crop 的选择,然后渲染到JQueryMobile,它在直接运行该页面时工作,但如果从另一个页面重定向到那个页面各种人口不工作。请帮我...

我的页面 - -

<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<?php
require_once('calendar/classes/tc_calendar.php');
?>
<!DOCTYPE html>
<html>
    <head>
        <title></title>            
        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
    <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
        <script language="javascript" src="calendar/calendar.js"></script>
        <link href="calendar/calendar.css" rel="stylesheet" type="text/css">      
        <!--<script src="jquery.js"></script>-->            
    </head>     
    <body>
        <script>
            $(document).ready(function() {
                $("#crop").change(function(){
                    $.ajax({
                        type:'GET',
                        url :'variety.php',
                        dataType:"json",                            
                        data: ({crop: $('#crop').val()}),
                        success : function(data){

                            $("#variety").html(data).selectmenu('refresh', true);                                
                        },
                        error : function(data){
                            //                        alert("Error"+data);
                        }
                    });

                });
            });
        </script>
        <script>
            function onSuccess(data, status)
            {
                data = $.trim(data);
                $("#notification").text(data);
            }

            function onError(data, status)
            {
                // handle an error
            }       

            $(document).ready(function() {
                $("#submit").click(function(){

                    var formData = $("#myform").serialize();

                    $.ajax({
                        type: "POST",
                        url: "offerReq_save.php",
                        cache: false,
                        data: formData,
                        success: onSuccess,
                        error: onError
                    });

                    return false;
                });
            });
        </script>

        <?php
        session_start();
        //$_SESSION["user_id"] = 10;
        $_SESSION["type"] = $_GET['type']; //"farmer offer";
        $_SESSION["ref"] = $_GET['ref']; //"new";
        $_SESSION["ictype"] = $_GET['ictype']; //"crop";
        // $_SESSION["usertype"] = "farmer";
        $types = $_SESSION["type"];
        $con = mysql_connect("localhost", "root", "itemfile");
        if (!$con) {
            die('Could not Connect:' . mysql_error());
        }
        mysql_select_db("agropiamob", $con);
        $tests = mysql_query("select * from m01_crop_master"); // or die("Note: " . mysql_error());       
        mysql_close($con);
        ?>
        <section id="page1" data-role="page">               
            <header data-role="header"><h1>Header</h1></header>
            <div data-role="content" class="content">
                <form id="myform">
                    <div data-role="fieldcontain">
                        <label for="type" class="select">Type :</label>
                        <select name="type" id="type" data-native-menu="false">
                            <option value="Product">Product</option>
                            <option value="Service">Service</option>
                            <option value="Bank">Bank</option>
                            <option value="Insurance">Insurance</option>
                        </select>
                    </div>                                        

                        <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-native-menu="false">
                            </select>
                        </div>                                                                     
                    <div data-role="fieldcontain">
                        <label id="locationLabel" for="location" class="select">Location :</label>
                        <input type="text" name="location" id="location">
                    </div>
                    <div data-role="fieldcontain">
                        <label for="terms" class="select">Terms :</label>
                        <select name="terms" id="terms" data-native-menu="false">
                            <option value="FOB">FOB</option>
                            <option value="CIF">CIF</option>
                        </select>
                    </div>
                    <div data-role="fieldcontain">                        
                        <!--<input name="mydate" id="mydate" type="date" data-role="datebox" data-options='{"mode": "calbox"}'>                        -->
                        <!--<label for="mydate" class="select">Date :</label>-->
                        <table border="0" cellspacing="0" cellpadding="2">
                            <tr>
                                <td nowrap>Date :</td>
                                <td><?php
                    $myCalendar = new tc_calendar("mydate", true, false);
                    $myCalendar->setIcon("calendar/images/iconCalendar.gif");
                    // $myCalendar->setDate(date('d'), date('m'), date('Y'));//
                    $myCalendar->setPath("calendar/");
                    $myCalendar->setYearInterval(2000, 2015);
                    $myCalendar->dateAllow('2008-05-13', '2015-03-01');
                    $myCalendar->setDateFormat('j F Y');
                    $myCalendar->setHeight(350); //
                    //$myCalendar->autoSubmit(true, "form1");//
                    $myCalendar->setAlignment('left', 'bottom');
                    //$myCalendar->setSpecificDate(array("2011-04-01", "2011-04-04", "2011-12-25"), 0, 'year');
                    //$myCalendar->setSpecificDate(array("2011-04-10", "2011-04-14"), 0, 'month');
                    //$myCalendar->setSpecificDate(array("2011-06-01"), 0, '');
                    $myCalendar->writeScript();
                    ?></td>
                               <!-- <td><input type="button" name="button" id="button" value="Check the value" onClick="javascript:alert(this.form.mydate.value);"></td>-->
                            </tr>
                        </table>
                    </div>

                    <div data-role="fieldcontain">
                        <!--<label for="validity">Validity :</label>
                        <input name="validity" id="validity" type="date" data-role="datebox" data-options='{"mode": "calbox"}'>-->
                        <table border="0" cellspacing="0" cellpadding="2">
                            <tr>
                                <td nowrap>Validity :</td>
                                <td><?php
                                    $myCalendar = new tc_calendar("validity", true, false);
                                    $myCalendar->setIcon("calendar/images/iconCalendar.gif");
                                    // $myCalendar->setDate(date('d'), date('m'), date('Y'));//
                                    $myCalendar->setPath("calendar/");
                                    $myCalendar->setYearInterval(2000, 2015);
                                    $myCalendar->dateAllow('2008-05-13', '2015-03-01');
                                    $myCalendar->setDateFormat('j F Y');
                                    $myCalendar->setHeight(350); //
                                    //$myCalendar->autoSubmit(true, "form1");//
                                    $myCalendar->setAlignment('left', 'bottom');
                                    //$myCalendar->setSpecificDate(array("2011-04-01", "2011-04-04", "2011-12-25"), 0, 'year');
                                    //$myCalendar->setSpecificDate(array("2011-04-10", "2011-04-14"), 0, 'month');
                                    //$myCalendar->setSpecificDate(array("2011-06-01"), 0, '');
                                    $myCalendar->writeScript();
                    ?></td>
                               <!-- <td><input type="button" name="button" id="button" value="Check the value" onClick="javascript:alert(this.form.mydate.value);"></td>-->
                            </tr>
                        </table>
                    </div>
                    <div data-role="fieldcontain">
                        <label id="payment_termsLabel" for="payment_terms" class="select">Payment Terms :</label>
                        <input type="text" name="payment_terms" id="payment_terms">
                    </div>                       
                    <div data-role="fieldcontain">
                        <label for="remarks">Remarks :</label>
                        <textarea name="remarks" id="remarks" cols="10" rows="3"></textarea>
                    </div>
                    <div data-role="fieldcontain">
                        <label for="freq" class="select">Frequency :</label>
                        <select name="freq" id="freq" data-native-menu="false">
                            <option value="Daily">Daily</option>
                            <option value="Weekly">Weekly</option>
                            <option value="Monthly">Monthly</option>
                        </select>
                    </div>
                    <div data-role="fieldcontain">                    
                        <button type="submit" id="submit" data-inline="true">Submit</button>
                        <button type="reset" data-inline="true">Cancel</button>
                        <h3 id="notification"></h3>
                    </div>
                </form>
            </div>
            <footer data-role="footer"><h1>Footer</h1></footer>
        </section>
    </body>
</html>
4

1 回答 1

1

$(document).ready(function() {<--这是你的问题。当您使用 jQM 时,此事件仅触发一次。它与这个库的 DOM 管理有关。

尝试添加这样的事件:

$('#pageId').bind('pageshow', function(){

});

pageId 是您的<div data-role="page" id="pageId">.

查看此页面了解更多活动:jQM Docs - Events

于 2012-11-22T11:07:32.010 回答