我正在使用Mika Tuupola Chained Selects jQuery 插件为我的网站构建一个链式选择/下拉列表。
我动态地从两个数据库类别和子类别中提取选项,如下所示:
类别:
<?php
$query="SELECT * FROM categories";
$result = mysql_query ($query);
echo"<select name='cselect1' id='cat'><option value=''>Please Select A Category</option>";
// printing the list box select command
while($catinfo=mysql_fetch_array($result)){//Array or records stored in $nt
echo "<option value=\"".htmlspecialchars($catinfo['number'])."\">".$catinfo['cat']."</option>";
}
echo"</select>";
?>
和子类别
<?php
$query="SELECT * FROM subcategories";
$result = mysql_query ($query);
echo"<select name='sselect1' id='subcat'><option value=''>Sub Category</option>";
// printing the list box select command
while($catinfo=mysql_fetch_array($result)){//Array or records stored in $nt
echo "<option value='".htmlspecialchars($catinfo['subcat'])."' class='".$catinfo['catnumber']."'>".$catinfo['subcat']."</option>";
}
echo"</select>";
?>
这呼应了这样的事情:
<select id="cat" name="cselect1">
<option value="0">Please Select A Category</option>
<option value="1">Restaurants</option>
<option value="2">Food</option>
<option value="3">Nightlife</option>
<option value="4">Shops</option>
</select>
<select id="subcat" name="sselect1">
<option value="">Sub Category</option>
<option class="1" value="American">American</option>
<option class="2" value="Specialty Food">Specialty Food</option>
<option class="3" value="Bars">Bars</option>
<option class="4" value="Computers">Computers</option>
</select>
这是我的jQuery:
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script src="../public/scripts/chain.js" type="text/javascript"></script>
<script type="text/javascript">
$("#subcat").chained("#cat");
</script>
但由于某种原因,它不起作用?为什么是这样?
感谢您对此的所有帮助!