jQuery实现三级联动代码如下
<!DOCTYPE html>
<html>
<head>
<meta  http-equiv="content-type" content="text/html;charset=utf-8"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>三级联动</title>
<script src="../bootstrap/js/jquery-1.11.2.min.js"></script>
</head>
<body>
<select id="sheng"></select>
<select id="shi"></select>
jquery实现ajax<select id="qu"></select>
</body>
<script type="text/javascript">$(document).ready(function(e) {
loadsheng();
loadshi();
loadqu();
$("#sheng").click(function() {
loadshi();
loadqu();
})
$("#shi").click(function() {
loadqu();
})
})
function loadsheng() {
var pcode = "0001";
$.ajax({
type: "POST",
url: "sanjichuli.php",
async: false,
data: { pcode: pcode },
dataType: "TEXT",
success: function(data) {
//alert(data);
var hang = data.split("|");
var str = "";
for(var i = 0; i < hang.length; i++) {
var lie = hang[i].split("^");
str = str + "<option value='" + lie[0] + "'>" + lie[1] + "</option>";
}
$("#sheng").html(str);
}
});
}
function loadshi() {
var pcode = $("#sheng").val();
$.ajax({
type: "POST",
url: "sanjichuli.php",
async: false,
data: { pcode: pcode },
dataType: "TEXT",
success: function(data) {
var hang = data.split("|");
var str = "";
for(var i = 0; i < hang.length; i++) {
var lie = hang[i].split("^");
str = str + "<option value='" + lie[0] + "'>" + lie[1] + "</option>";
}
$("#shi").html(str);
}
});
}
function loadqu() {
var pcode = $("#shi").val();
$.ajax({
type: "POST",
url: "sanjichuli.php",
async: false,
data: { pcode: pcode },
dataType: "TEXT",
success: function(data) {
var hang = data.split("|");
var str = "";
for(var i = 0; i < hang.length; i++) {
var lie = hang[i].split("^");
str = str + "<option value='" + lie[0] + "'>" + lie[1] + "</option>";            }
$("#qu").html(str);
}
});
}</script>
</html>
处理界⾯代码
<?php
include("../DBDA.class.php");
$db = new DBDA();
$pcode = $_POST["pcode"];
$sql = "select * from chinastates where parentareacode='{$pcode}'";
echo$db->strquery($sql,1);
实现效果如下

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。