日期:2014-05-17  浏览次数:20687 次

谁可以写个2级联动select 的例子 看看
写个简单的例子 写一下注释 研究一下 谢了 各位大虾

------解决方案--------------------
function college2subject(collegeid)
{
var allcount=0;
subjectArray=new Array();
<?php
$link=mysql_connect("localhost","root","123");
$db_selected=mysql_select_db("test");
 mysql_query("SET NAMES utf8");

 
$sql="select * from subject";
$result=mysql_query($sql);
$count=0;
while($myrow=mysql_fetch_array($result))
{

 echo "subjectArray[".$count."]=new Array('".$myrow['subject_id']."','".$myrow['subject_name']."',
'".$myrow['college_id']."')\n";


$count++;
}
echo "allcount=$count;";

?>

document.studentform.subject.length=0;
document.studentform.subject.options[document.studentform.subject.length]=new Option("所有专业","");
var college_id=collegeid;
var i;
for(i=0;i<allcount;i++)
{
if(subjectArray[i][2]==college_id)
{
document.studentform.subject.options[document.studentform.subject.length]=new Opiton(subjectArray[i][1],subjectArray[i][0]);
alert("ok");
}
}
}
alert("ok");
</script>


</head>

<body>
<?php
$link=mysql_connect("localhost","root","123");
$db_selected=mysql_select_db("test");
mysql_query("SET NAMES utf8");

$sql="select * from college";
 
$result=mysql_query($sql)or die (mysql_error());

?>

<form id="studentform" name="studentform" method="post" action="">
<table width="200" border="1">
<tr>
<td>请选择学院</td>
<td>
<label>
<select name=college" onChange="college2subject(this.options[this.selectedIndex].value)">
<option>所有学院</option>
<?php
while($myrow1=mysql_fetch_array($result))
{
?> 
<option value="<?php echo $myrow1["college_id"];?>" selected="selected">
<?php echo $myrow1["college_name"];?></option>

<?php } ?>

------解决方案--------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>select筛选_water</title>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
</head>
<body>
<span>板块</span>
<select name="water1" id = "water1">
<option value="" selected>请选择</option>
<option value="water1">water1</option>
<option value="water2">water2</option>
<option value="water3">water3</option>
<option value="water4">water4</option>
<option value="water5">water5</option>
</select>
<span>二级板块</span>
<select name="water2">
<option value="" selected>请选择</option>

<option value="water5-5" rel="water5">water5-5</option>
<