我的industry.php代码:
<?php
$parent = array('1'=>'电子及家电','2'=>'照明','3'=>'车辆及配件','4'=>'机械','5'=>'五金工具','6'=>'建材');
$child = array('1'=>array('16'=>'家用电器'));
$id = $_GET['id'];
if ($_GET['name'] == 'p') {
echo json_encode($parent);
} else {
echo json_encode($child[$id]);
}
?>
industry.html代码:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="saigel.js"></script>
</head>
<body>
<div class="init a_industry">
<select id="parent">
<option value="0">请选择</option>
</select>
<select id="child"><option value="0">请选择</option></select>
</div>
</body>
</html>我的saigel.js代码:
Saigel.init_industry = function() {
var parent = $("#parent");
var child = $("#child");
var stat = 1; $.getJSON("industry.php?name=p", function(data){
html = '<option value="0">请选择</option>';
for(var key in data) {
html += '<option value="' + key + '">' + data[key] + '</option>';
}
parent.html(html);
return false;
});
parent.change(function() {
$.getJSON("industry.php?id=" + this.value, function(data){
html = '<option value="0">请选择</option>';
for(var key in data) {
html += '<option value="' + key + '">' + data[key] + '</option>';
}
child.html(html);
});
return false;
});
}
问题是我选中第一个电子及家电的时候,select框返回的还是请选择,不知道哪里有问题,各位请帮忙!
<?php
$parent = array('1'=>'电子及家电','2'=>'照明','3'=>'车辆及配件','4'=>'机械','5'=>'五金工具','6'=>'建材');
$child = array('1'=>array('16'=>'家用电器'));
$id = $_GET['id'];
if ($_GET['name'] == 'p') {
echo json_encode($parent);
} else {
echo json_encode($child[$id]);
}
?>
industry.html代码:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="saigel.js"></script>
</head>
<body>
<div class="init a_industry">
<select id="parent">
<option value="0">请选择</option>
</select>
<select id="child"><option value="0">请选择</option></select>
</div>
</body>
</html>我的saigel.js代码:
Saigel.init_industry = function() {
var parent = $("#parent");
var child = $("#child");
var stat = 1; $.getJSON("industry.php?name=p", function(data){
html = '<option value="0">请选择</option>';
for(var key in data) {
html += '<option value="' + key + '">' + data[key] + '</option>';
}
parent.html(html);
return false;
});
parent.change(function() {
$.getJSON("industry.php?id=" + this.value, function(data){
html = '<option value="0">请选择</option>';
for(var key in data) {
html += '<option value="' + key + '">' + data[key] + '</option>';
}
child.html(html);
});
return false;
});
}
问题是我选中第一个电子及家电的时候,select框返回的还是请选择,不知道哪里有问题,各位请帮忙!
解决方案 »
- 如何提高Apache服务器的上传速度
- php 站内搜索 模糊匹配怎么实现
- 验证码在哪加时间的字符串才可以避免读缓存
- 请教一个正则表达式
- PHP 分页在地址加入&就会出错,怎么办?
- Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate
- 我要怎么才把1234连续的四个数字分开,并且保存在一个数组$exl中。怎么我都不成功那?!
- 同时使用PHPLIB的Template类和Mysql类,不能重复显示记录
- 求教:能不能动态修改html(php)文件的内容,并能保存?
- 大家接招了!!我要在雙擊時不選中文本,在鼠標移到上面時變為手形鼠標。單擊<a>的連接時,實際不連接任何頁面!!!
- 留言版纠错
- #1064救命
industry.php加载了好几次,
{"1":"\u7535\u5b50\u53ca\u5bb6\u7535","2":"\u7167\u660e","3":"\u8f66\u8f86\u53ca\u914d\u4ef6","4":"\u673a\u68b0","5":"\u4e94\u91d1\u5de5\u5177","6":"\u5efa\u6750"}
加载都是那些
可是不知道js哪里出错了,上面的例子是可以允许的如果配好了php环境。
这个请求的响应信息呢
为何最后执行的总是industry.php?name=p
这些数据没问题啊。。json数据啊。你输出的是json啊