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>
<!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>
$rt='<select name="type2" id="type2">';
改为
$rt='<select name="type_tow" id="type_two">';
echo $_POST['type_two']; //没有值?
$.ajax({
url: "../admin/type.php?id="+$("#type1").val(),
success: function(data) {
$("#type2").html(data);
}
});
url: "../admin/type.php?id="+$("#type1").val(),
cache: false,
success: function(data) {
$("#type2").html(data);
}
});