HTML页面代码如下
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
</head>
<script type="text/javascript" src="../js/jquery-1.7.2.js"></script>
<script language="javascript">
$(document).ready(function(){
  $("#type1").change(function(){                //jquery中change()函数
    $("#type2").load("../admin/type.php?id="+$("#type1").val());    //jqueryajax中load()函数
  });
});
</script>
<body>
<form id="form1" name="form1" method="post" action="test.php"><select name="type1" id="type1">
<option value="-1">--第一分类--</option>
(#section name=u loop=$type#)
<option value="(#$type[u].pt_id#)">--(#$type[u].pt_name#)--</option>
(#/section#)
</select>
<span id="type2">
<select name="type_two" id="type_two">
<option value="-2">--第二分类--</option>
</select>
</span>
<input type="submit" name="button" id="button" value="提交" />
</form>
</body>
</html>ajax联动页面代码如下<?php
define('DIR',substr(dirname(__FILE__),0,strlen(dirname(__FILE__))-5));
require DIR."include/smarty.inc.php";
require DIR."include/mysql.inc.php";
header("Content-type:text/html;charset=gb2312");  
$id=$_GET['id'];
$sql="select * from product_type_two where pt_id=$id";
$res=$admindb->execSQL($sql, $conn);
$rt='<select name="type2" id="type2">';
if($res)
{
foreach($res as $k=>$val)
{

$rt.='<option value="'.$val['tt_id'].'">'.$val['tt_name'].'</option>';
}
}
else
{
$rt.="<option value='null'>暂无分类</option>";
}
$rt.='</select>';
echo $rt;
?>
 现在的问题是联动功能显示完美 但是提交网页的时候第2级联动无值 查看网页源代码如下 网页显示正常- -但是第2级的html代码却没有 求指点- -<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
</head>
<script type="text/javascript" src="../js/jquery-1.7.2.js"></script>
<script language="javascript">
$(document).ready(function(){
  $("#type1").change(function(){                                                                                         //jquery中change()函数
    $("#type2").load("../admin/type.php?id="+$("#type1").val());                                     //jqueryajax中load()函数
  });
});
</script>
<body>
<form id="form1" name="form1" method="post" action="test.php"><select name="type1" id="type1">
<option value="-1">--第一分类--</option>
<option value="5">--电子商品--</option>
<option value="1">--男装--</option>
<option value="2">--女装--</option>
<option value="4">--首饰--</option>
</select>
<span id="type2">
<select name="type_two" id="type_two">
<option value="-2">--第二分类--</option>
</select>
</span>
<input type="submit" name="button" id="button" value="提交" />
</form>
</body>
</html>

解决方案 »

  1.   

    type.php中下拉列表的name属性值写错了。
    $rt='<select name="type2" id="type2">';
    改为
    $rt='<select name="type_tow" id="type_two">';
      

  2.   

    $rt='<select name="type_two" id="type_two">';
      

  3.   

    - -这个改了没用 另外一边还是没post到值- -
      

  4.   

    后台取值的代码也写错了?
    echo $_POST['type_two']; //没有值?
      

  5.   

    顺便能问下这种下拉因为缓存问题会还是显示错误 把smarty的缓存清空就能正常么?
      

  6.   

    smarty不清楚,但jQuery默认会缓存,可以设置cache参数为false禁止缓存(用ajax()方法代替load()方法):
    $.ajax({
    url: "../admin/type.php?id="+$("#type1").val(),
    success: function(data) {
    $("#type2").html(data);
    }
    });
      

  7.   

    $.ajax({
        url: "../admin/type.php?id="+$("#type1").val(),
        cache: false,
        success: function(data) {
            $("#type2").html(data);
        }
    });