<script language="javascript" src="/script/script_jquery.old.js"></script>
<script language="javascript" type="text/javascript">var j= jQuery.noConflict(true);</script>
<option value="0">--请选择--</option>
<!--{loop $_SGLOBAL['category'] $key $value}-->
<option value="{$key}">{$value}</option>
<!--{/loop}-->
</select>
<select name="classname2" style="WIDTH: 130px" id="classname2">
<option value="0">--请选择--</option>
</select>
js:
//获取二级分类
function getCategory(classid){
j.get("./xin/xin_ajax_category.php",{classid:classid},function(data){
var results=eval("("+data+")");
var list = document.getElementById("classname2");
list.options.length = 0;
list.options.add(new Option("--请选择--","0"));
for (var i = 0; i < results.length; i++) {
list.options.add(new Option(results[i].childname,results[i].childid)); //text ,value
}
});
}
xin_ajax_category.php:
<?php
include_once('../common.php');
$classid=intval($_REQUEST['classid']);
//flag
if(!empty($classid)){
$category_arr="";
$sql="SELECT b.childid,b.childname FROM `xin_works_category_class` a, `xin_works_category_child` b WHERE a.classid=b.pid and a.classid=$classid order by a.classid ,b.childid";
$handle=$_SGLOBAL['db']->query($sql);
while($value=$_SGLOBAL['db']->fetch_array($handle)){
$value['childname']=convertToUTF8($value['childname']);
$category_arr[]=$value;
unset($value);
}
unset($handle);
//print_r($category_arr);
echo json_encode($category_arr);
}
?>
当你一步一个脚印的走过