实用的mysql+ajax+php 三级级联下拉框

添加时间:15-06-03 所属分类:PHP工具与代码
  http://blog.sina.com.cn/s/blog_5ffc4bac0100jgms.html

1,昨天弄了一个简单的三级级联下拉框。超级实用。

index.php:
[code]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Ajax联动菜单</title>
<script language="javascript" type="text/javascript" src="aa.js"></script>
</head>
<body>

<form>
<label>
<select name="sel" id="sel" onChange="showMenu(this.value);">
<option>一级分类</option>
<?php
$conn = mysql_connect('localhost', 'root', '') or die('Could not connect: ' . mysql_error());
mysql_select_db('fitment', $conn) or die ('Can\'t use database : ' . mysql_error());
mysql_query("set names 'gb2312'");
$str = "SELECT * FROM `fitment_sort` where supid = '0' ORDER BY `id` ASC";
$result = mysql_query($str) or die("Invalid query: " . mysql_error());
if($result)
{
while ($arr = mysql_fetch_array($result)){
echo <<<EOD
<option value={$arr["id"]}>{$arr["name"]}</option>
EOD;
}
}
mysql_close($conn);
?>
</select>
</label>


<label>
<select name="sel2" id="sel2" onChange="showMenu2(this.value)">
<option>二级分类</option>
</select>
</label>



<label>
<select name="sel3" id="sel3">
<option>三级分类</option>
</select>
</label>
</form>
<input type=button value="send value" onClick="alert(document.getElementByIdx('sel').options[document.getElementByIdx('sel').selectedIndex].text + '-' + document.getElementByIdx('sel2').options[document.getElementByIdx('sel2').selectedIndex].text + '-' + document.getElementByIdx('sel3').options[document.getElementByIdx('sel3').selectedIndex].text)">
</body>
</html>[/code]
  • 2
  • 3

前篇:Ji'nan city police began public law enfo... 后篇:济南市面大量“即食红枣”属虚标 是否清洗杀...
发表我的评论


推荐文章   济南将开通58条旅游公交线路 线路票价全...   媒体卧底茶叶市场爆惊人内幕:香味可调...   奖励分没了,会影响孩子学特长?   买房前、买房中、买房后 买房全程防“坑...   “你们的建议真的帮不了我…”这大概是...
随机文章   php结合phantomjs实现网页截屏、抓取js...   PHP调用科大讯飞语音服务   用php实现Google /Baidu Ping服务快速收...   php输出乱码的解决   对 mysql Illegal mix of collations (...
广告

其他推荐

因为本站所有内容均转载自其它媒体,本意为公众提供免费服务,但并不代表本网赞同其观点,也不能对其真实性验证负责,如稿件版权单位或个人不想在本网发布,请与我联系,本人会立即将其撤除,谢谢.联系方式:atseashawk@163.com QQ:99289555