尝试使用jQuery和Ajax创建动态相关选择框。
一切都很好,但我在<fieldset>
我注意到当我加载jquery api(试过不同版本)时会发生这种情况。
来源:
解释
<div>
<label>Diplome :</label>
<select name="diplome" class="diplome">
<option selected="selected" value="0">Choisir Diplome</option>
<?php
include('db.php');
$sql=mysql_query("select * from diplome");
while($row=mysql_fetch_array($sql))
{
echo '<option value="'.$row['id_diplome'].'">'.$row['libelle'].'</option>';
} ?>
</select>
<br/>
<br/>
<label>Section :</label>
<select name="section" class="section">
<option selected="selected">Choisir section</option>
</select>
</div>
脚本:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
$(".diplome").change(function()
{
var id=$(this).val();
var id_String = 'id='+ id;
$.ajax
({
type: "POST",
url: "action.php",
data: id_String,
cache: false,
success: function(sectiondata)
{
$(".section").html(sectiondata);
}
});
});
});
</script>
动作:
<?php
$hostname = "localhost";
$user = "root";
$password = "";
$database = "sondage";
$bd = mysql_connect($hostname, $user, $password)
or die("DB Connection Failed!");
mysql_select_db($database, $bd) or die("DB Connection Failed!");
if($_REQUEST['id'])
{
$id=$_REQUEST['id'];
if($id==0){echo "<option>Choisir Section</option>";}else{
$sql=mysql_query("select * from section where id_diplome='$id'");
while($row=mysql_fetch_array($sql))
{
echo '<option value="'.$row['id_section'].'">'.$row['libelle'].'</option>';
}
}
}
?>
控制台错误:
Uncaught TypeError: $.backstretch is not a function
at HTMLDocument.<anonymous> (scripts.js:7)
at j (jquery-1.11.1.min.js:2)
at Object.fireWith [as resolveWith] (jquery-1.11.1.min.js:2)
at Function.ready (jquery-1.11.1.min.js:2)
at HTMLDocument.J (jquery-1.11.1.min.js:2)
如果有人有想法,谢谢。