require_once一会儿

时间:2013-01-07 20:06:36

标签: php jquery

我有这段代码:

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
    if($i++%2==0){
       $color="#FFFFFF";
    }else{
       $color="#CCCCCC";
    }

    ?>

    <tr bgcolor='<?php echo $color; ?>' onmouseover="this.style.background='#ABFB04';" onmouseout="this.style.background='<?php echo $color; ?>';">
    <?php

echo "<td class=tablelist>";

echo $row["ICAO"] . '</td><td class=tablelist>';

echo $row["Name"] . '</td><td class=tablelist>';

echo $row["WeightEmpty"] . '</td><td class=tablelist>';

echo $row["WeightFull"] . '</td><td class=tablelist>';

echo $row["CargoFull"] . '</td><td class=tablelist>';

echo $row["Range"] . '</td><td class=tablelist>';

echo $row["Price"] . '</td><td class=tablelist>';

echo $row["FirstClassSeats"] . '</td><td class=tablelist>';

echo $row["BusinessClassSeats"] . '</td><td class=tablelist>';

echo $row["EconomyClassSeats"]. '</td><td class=tablelist>';

echo "<img class='editaircraft' src='./images/info.png'></td></tr>"; 

?>
<script>
    $(function() {
        $( "#editaircraftdialog" ).dialog({
            autoOpen: false,
            width: 425
        });

        $( ".editaircraft" ).click(function() {
            $( "#editaircraftdialog" ).dialog( "open" );
            return false;
        });
    }); 
</script>

<div id="editaircraftdialog" title="Edit Aircraft">
    <?php require_once('./new_aircraft.php'); ?> 
</div>

<?php
}

echo "</table>";
$pagination->render();
?>

问题在于:

<div id="editaircraftdialog" title="Edit Aircraft">
        <?php require_once('./new_aircraft.php'); ?> 
    </div>

如果我偶尔使用require,它就不起作用了。但如果要求已经过了一段时间,它会很有趣。如果我更改了require_once并且我放了文本,那就很有趣。

问题是我看到require_once的内容出了这样的对话框:http://i50.tinypic.com/k1aslk.png

当它到达<div>时停止。

new_aircraft.php

<script>
    $(function() {
        $("#insertaircraft")
            .button()
            .click(function(event) {
        });
    });
</script>

<form action="new_aircraft_process.php" method="post" enctype="application/x-www-form-urlencoded">
    <table>

    <tr><td class="forms">ICAO:</td><td><input maxlength="4" type="text" name="icao" size="30"/></td></tr>

    <tr><td class="forms">Name:</td><td><input type="text" name="name" size="30"/></td></tr>

    <tr><td class="forms">Weight Empty:</td><td><input type="text" name="weightempty" size="30"/></td></tr>

    <tr><td class="forms">Weight Full:</td><td><input type="text" name="weightfull" size="30"/></td></tr>

    <tr><td class="forms">Cargo Full:</td><td><input type="text" name="cargofull" size="30"/></td></tr>

    <tr><td class="forms">Cruise Speed:</td><td><input type="text" name="cruisespeed" size="30"/></td></tr>

    <tr><td class="forms">Range:</td><td><input type="text" name="range" size="30"/></td></tr>

    <tr><td class="forms">Price:</td><td><input type="text" name="price" size="30"/></td></tr>

    <tr><td class="forms">Number Classes:</td><td><select name="numberclasses" id="numberclasses">
        <option value="0">Select Number of Classes</option>
        <?php
        echo '<option value="1">One Classes (Economy)</option>';
        echo '<option value="2">Two Classes (Business & Economy)</option>';
        echo '<option value="3">Three Classes (First, Business & Economy)</option>';
        ?>
    </select></td></tr>



    <tr><td class="forms">First Class Seats:</td><td><input disabled="disabled" type="text" id="firstclassseats" name="firstclassseats" size="30"/></td></tr>

    <tr><td class="forms">Business Class Seats:</td><td><input disabled="disabled" type="text" id="businessclassseats" name="businessclassseats" size="30"/></td></tr>

    <tr><td class="forms">Economy Class Seats:</td><td><input disabled="disabled" type="text" id="economyclassseats" name="economyclassseats" size="30"/></td></tr>

<script type="text/javascript">

$("#numberclasses").change(function() {
value = $(this).val();

str = parseInt(value);

switch(str)
  {
    case 0:
    $(document).ready(function() {
        $("#firstclassseats").attr("disabled","disabled");
        $("#businessclassseats").attr("disabled","disabled");
        $("#economyclassseats").attr("disabled","disabled");
});
    break;

    case 1:
    $(document).ready(function() {
        $("#economyclassseats").removeAttr('disabled');
        $("#firstclassseats").attr("disabled","disabled");
        $("#businessclassseats").attr("disabled","disabled");
});
    break;

     case 2:
    $(document).ready(function() {
        $("#businessclassseats").removeAttr('disabled');
        $("#economyclassseats").removeAttr('disabled');
        $("#firstclassseats").attr("disabled","disabled");
});
    break;

    case 3:
    $(document).ready(function() {
        $("#firstclassseats").removeAttr('disabled');
        $("#businessclassseats").removeAttr('disabled');
        $("#economyclassseats").removeAttr('disabled');
});
    break;

  }
});

</script>

    <tr><td></td><td><input id="insertaircraft" type="submit" value="Insert Aircraft"/></td></tr>
    </table>
</form>

2 个答案:

答案 0 :(得分:3)

注意 _once 部分。一旦您包含该文件,在脚本退出并启动新实例之前,它将不会再次包含。这是设计的。如果您每次都想要该文件,请改用require()

答案 1 :(得分:2)

require_once更改为requireinclude。由于'一次',您的脚本将仅在第一次迭代时包含该文件。

requireinclude之间的区别在于,如果PHP无法找到该文件,require会因错误而破坏您的代码。

include会触发警告,但允许您的脚本继续播放。