我有这段代码,但我在chrome中遇到错误,未定义load_new_content_dr ...
<html>
<head>
<script lang="javascript" src="http://code.jquery.com/jquery-latest.js">
$(document).ready(function(){
$("#Dr_name").change(load_new_content_dr());
$("#day").change(load_new_content_day());
});
function load_new_content_dr(){
var selected_option_value=$("#Dr_name option:selected").val();
$.post("_add_reservasion.php", {option_value: selected_option_value},
function(data){
$("#day").html(data);
alert(data);
}
);
$.post("__add_reservasion.php",
function(data){
$("#time").html(data);
alert(data);
}
);
}
function load_new_content_day(){
var selected_day = $("#day option:selected").val();
$.post("__add_reservasion.php", {selected_day:selected_day},
function(data){
$("#time").html(data);
alert(data);
}
);
}
</script>
</head>
<body>
...
some codes for connecting database and other stiffs...
...
<!--======================doctore name=========================-->
<p>doctor name:</p>
<select name="Dr_name" id = "Dr_name" form="new" onchange="load_new_content_dr()">
<option value="null"></option>
<?php
while($row = mysqli_fetch_array($table))
{
$name = $row["name"];
if(isset($_POST["Dr_name"]) && $_POST["Dr_name"] == $name)
echo "<option value =$name selected>$name</option>";
else
echo "<option value =$name>$name</option>";
}
?>
</select><br><br><br>
<!--=========== day===============\\-->
<p>reservation day:</p>
<select name="day" id="day" form="new" onchange="load_new_content_day()"></select><br><br><br>
<!--hour-->
<p>time:</p>
<select name="time" id = "time" form = "new"></select><br><br>
<input type="submit" value="save">
<input type="submit" name="cancel" value="cancel">
</form>
</body>
</html>
看来Java脚本代码不起作用,因为起初在页面加载时,它们应该进行一些更改,而它们不会:(
最佳答案
如果指定script标签的src
属性,则其文本内容将被忽略。您应该改用两个脚本标签:
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
// ...
</script>
关于javascript - 为什么JavaScript无法正常工作?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42200135/