我有这个问题。
索引.php
<script type="text/javascript">
function edit(str){
var xmlhttp;
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
document.getElementById("editdialog").innerHTML=conection.responseText;
$( "#editdialog" ).dialog({
autoOpen: true,
width: 425
});
}
xmlhttp.open("GET","edit.php?id="+str,true);
xmlhttp.send();
}
</script>
$query=mysql_result(SELECT * FROM paises)
while ($row = mysql_fetch_assoc($query)) {
echo $row['pais'];
echo "<a href=\"#\" onclick=\"edit('".$row["ICAO"]."')\">Edit</a>";
}
?>
<div id="editdialog" title="Edit"></div>
和 edit.php 文件:
<script src="./jquery.js"></script>
<script src="./ui/jquery.ui.widget.js"></script>
<script src="./ui/jquery.ui.button.js"></script>
<script src="./ui/jquery.ui.core.js"></script>
<script src="./ui/jquery.ui.widget.js"></script>
<script src="./ui/jquery.ui.mouse.js"></script>
<script src="./ui/jquery.ui.button.js"></script>
<script src="./ui/jquery.ui.draggable.js"></script>
<script src="./ui/jquery.ui.position.js"></script>
<script src="./ui/jquery.ui.resizable.js"></script>
<script src="./ui/jquery.ui.dialog.js"></script>
<script src="./ui/jquery.ui.effect.js"></script>
<script>
$(function() {
$("#editaircraft")
.button()
.click(function(event) {
});
});
</script>
<?php
require_once ('config.php');
$icao = $_REQUEST["icao"];
echo '<tr><td class="forms">Number Classes:</td><td><select id="numberclasses" name="numberclasses">';
echo "<option value='0'>Select Number of Classes</option>";
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>";
echo '</select></td></tr>';
echo '<tr><td class="forms">First Class Seats:</td><td><input disabled="disabled" type="text" id="firstclassseats" name="firstclassseats" size="30" value=';
echo $row["FirstClassSeats"] . "></td></tr>";
echo '<tr><td class="forms">Business Class Seats:</td><td><input disabled="disabled" type="text" id="businessclassseats" name="businessclassseats" size="30" value=';
echo $row["BusinessClassSeats"] . "></td></tr>";
echo '<tr><td class="forms">Economy Class Seats:</td><td><input disabled="disabled" type="text" id="economyclassseats" name="economyclassseats" size="30" value=';
echo $row["EconomyClassSeats"] . "></td></tr>";
?>
<script>
$("#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>
<?php
echo "<tr><td><input id='editaircraft' type='submit' value='Edit Aircraft'></td></tr>";
echo "</table>";
?>
</form>
问题是这个脚本:
$("#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>
该脚本必须在函数中激活和停用选择的选择。但如果我在文件中这样做,一切都会完美。但是如果我想通过 index.php 和 Edit 链接来做,Ajax 会打开对话框,但脚本不起作用。我选择了该选项,但输入没有改变。