哪位有PHP导航栏的代码,带二级联动菜单的,共享一下
解决方案 »
- 模拟登陆如何后页面会自动跳转,如何获得当前页面的url
- 关于php的3des算法(与C语言的3des结果不一样)
- PNG,GIF缩略图背景透明函数.(都支持,就差一个缺点了[黑色的处理])
- 上传代码有问题?
- bluefish怎么预览阿
- +sqlite 在加载时报错(PHP Warning: PHP Startup: Cannot dynamically load sqlite3.so - dynamic modules are not support in Unknown
- 身份证号码的转换(急)在线等
- 求一个找出配对括号内容的正则表达式
- 求救,print 显示中文字符的困扰~~~~
- PHP如何开启DBF数据库中的MEMO类型资料 急!!!!!!!!!!!!
- 小弟想学php,怎么学起,会html+css
- 谁知道 m-v-m php的 网上购物网站程序?
经典的php二级联动菜单
<script language = "JavaScript">
var onecount;
onecount=0;
subcat = new Array();
<?
mysql_connect("localhost","root","");
mysql_select_db( "test" );
$sql = "select * from subject";
$result = mysql_query( $sql );
$count = 0;
while($res = mysql_fetch_row($result)){
?>
subcat[<?=$count?>] = new Array("<?=$res[0]?>","<?=$res[1]?>","<?=$res[2]?>");
<?
$count++;
}
echo "onecount=$count;";
?>
//联动函数
function changelocation(locationid)
{
document.myform.ctype.length = 0;
var locationid=locationid;
var i;
for (i=0;i < onecount; i++)
{
if (subcat[i][2] == locationid)
{
//var newOption1=new Option(subcat[i][1], subcat[i][0]);
//document.all.ctype.add(newOption1);
document.myform.ctype.options[document.myform.ctype.length] = new Option(subcat[i][1], subcat[i][0]);
}
}
}
</script>
<form method="post" name="myform" action="ru_query.php">
<select name="type" onChange="changelocation(document.myform.type.options[document.myform.type.selectedIndex].value)" size="1">
<option selected value="">请指定主分类</option>
<?
$sql = "select * from depart";
$result = mysql_query( $sql );
while($res = mysql_fetch_row($result)){
?>
<option value="<? echo $res[0]; ?>"><? echo $res[1]; ?></option>
<? } ?>
</select>
<select name="ctype">
<option selected value="">请指定小分类</option>
</select>
<input type="submit" name="Submit" value="搜索">
</form> 数据库机构如下表depart--------departID departName表subject-------subjectID subjectName departID
1.通过精选取得数据库的字段并且存入数组
2.定义自定义函数,遍历数组并且使用echo命令把$参数转化成js可以使用的变量
3.在js中使用<?自定义函数?>参数进行传递
4.通过js的new Option重新组织菜单选项