更改未触发的函数,javascript动态表单
我不知道这为什么不开火。当我测试代码时,表单会出现,但当我从第一个表单中选择时,不会出现任何情况。我确信无论出于什么原因,.change函数都不起作用更改未触发的函数,javascript动态表单,javascript,php,jquery,html,Javascript,Php,Jquery,Html,我不知道这为什么不开火。当我测试代码时,表单会出现,但当我从第一个表单中选择时,不会出现任何情况。我确信无论出于什么原因,.change函数都不起作用 <?php require("scripts/dbconnect.php"); $stmt = $db->prepare('SELECT name FROM sets'); $stmt->execute(); $data = $stmt->fetchAll(); ?> <select id="first-c
<?php
require("scripts/dbconnect.php");
$stmt = $db->prepare('SELECT name FROM sets');
$stmt->execute();
$data = $stmt->fetchAll();
?>
<select id="first-choice">
<?php foreach ($data as $row): ?>
<option><?=$row["name"]?></option>
<?php endforeach ?>
</select>
<br />
<select id="second-choice">
<option>Please choose from above</option>
</select>
<script language=JavaScript>
$("#first-choice").change(function() {
$("#second-choice").load("getter.php?choice=" + $("select#first-choice option").filter(":selected").val());
});
</script>
首先,您需要确保JQuery包含在页面上,而不是您的帖子中。其次,确保在DOM就绪时调用代码
$(document).ready(function(){
$("#first-choice").change(function() {
$("#second-choice").load("getter.php?choice=" + $("select#first-choice option").filter(":selected").val());
});
});
脚本标记是否在select之后,例如在您的问题中?或者是在你页面的首页。谢谢,Jquery没有包括在内