怎么个代码处理?? /* ************************************************************************ * FUNCTION: showCategory * * DESCRIPTION: When the value of the store-navigation department * drop-down is changed, this function is called, which * displays or hides the appropriate list of classes * for the selected department. The lists of classes * are seperated into <DIV>s by department. * * INPUTS: None. * * OUTPUTS: None * * RETURNS: Nothing * * AUTHOR: Jeremy Ragan DPJNR0 ************************************************************************ */ function showCategory() { //get the value of the department drop-down var option = document.frmNavSearch.strCatalogDept.selectedIndex; var option_value = document.frmNavSearch.strCatalogDept.options[option].value;
if (option_value != '') { //If something other than the default '-- Select --' has been chosen if (blnNS) { if (eval(strLayerSwitch + '[\'div' + option_value + '\']')) { eval(strLayerSwitch + '[\'div' + option_value + '\']' + strStyleSwitch + '.visibility=\'visible\';'); } } else if (blnGecko) { if (eval(strLayerSwitch + '(\'div' + option_value + '\')')) { eval(strLayerSwitch + '(\'div' + option_value + '\')' + strStyleSwitch + '.visibility = \'visible\';'); } } else if (blnIE) { if (eval(strLayerSwitch + '[\'div' + option_value + '\']')) { eval(strLayerSwitch + '[\'div' + option_value + '\'].className=\'categoriesSHOW\';'); } } //If a department has previously been selected and is not equal to the new // value of the department drop-down, then we hide the <div> holding the // classes associated with it. if (objSelectedCat != '' && objSelectedCat != option_value) { if (blnNS) { if (eval(strLayerSwitch + '[\'div' + objSelectedCat + '\']')) { eval(strLayerSwitch + '[\'div' + objSelectedCat + '\']' + strStyleSwitch + '.visibility=\'hidden\';'); } } else if (blnGecko) { if (eval(strLayerSwitch + '(\'div' + objSelectedCat + '\')')) { eval(strLayerSwitch + '(\'div' + objSelectedCat + '\')' + strStyleSwitch + '.visibility = \'hidden\';'); } } else if (blnIE || blnGecko) { if (eval(strLayerSwitch + '[\'div' + objSelectedCat + '\']')) { eval(strLayerSwitch + '[\'div' + objSelectedCat + '\'].className=\'categoriesHIDE\';'); } } }
//Set the selected department to the current value in the department drop-down objSelectedCat = option_value;
} else { //If the department drop down value has been changed to the default '-- Select --', then we hide the previously-displayed classes if (blnNS) { if (eval(strLayerSwitch + '[\'div' + objSelectedCat + '\']')) { eval(strLayerSwitch + '[\'div' + objSelectedCat + '\']' + strStyleSwitch + '.visibility=\'hidden\';'); } } else if (blnGecko) { if (eval(strLayerSwitch + '(\'div' + objSelectedCat + '\')')) { eval(strLayerSwitch + '(\'div' + objSelectedCat + '\')' + strStyleSwitch + '.visibility = \'hidden\';'); } } else if (blnIE) { if (eval(strLayerSwitch + '[\'div' + objSelectedCat + '\']')) { eval(strLayerSwitch + '[\'div' + objSelectedCat + '\'].className=\'categoriesHIDE\';'); } }
//Set the selected department to nothing objSelectedCat = ''; } } 这个也是onchange但是没看明白。
/*
************************************************************************
* FUNCTION: showCategory
*
* DESCRIPTION: When the value of the store-navigation department
* drop-down is changed, this function is called, which
* displays or hides the appropriate list of classes
* for the selected department. The lists of classes
* are seperated into <DIV>s by department.
*
* INPUTS: None.
*
* OUTPUTS: None
*
* RETURNS: Nothing
*
* AUTHOR: Jeremy Ragan DPJNR0
************************************************************************
*/
function showCategory() {
//get the value of the department drop-down
var option = document.frmNavSearch.strCatalogDept.selectedIndex;
var option_value = document.frmNavSearch.strCatalogDept.options[option].value;
if (option_value != '') { //If something other than the default '-- Select --' has been chosen
if (blnNS) {
if (eval(strLayerSwitch + '[\'div' + option_value + '\']')) {
eval(strLayerSwitch + '[\'div' + option_value + '\']' + strStyleSwitch + '.visibility=\'visible\';');
}
} else if (blnGecko) {
if (eval(strLayerSwitch + '(\'div' + option_value + '\')')) {
eval(strLayerSwitch + '(\'div' + option_value + '\')' + strStyleSwitch + '.visibility = \'visible\';');
}
} else if (blnIE) {
if (eval(strLayerSwitch + '[\'div' + option_value + '\']')) {
eval(strLayerSwitch + '[\'div' + option_value + '\'].className=\'categoriesSHOW\';');
}
} //If a department has previously been selected and is not equal to the new
// value of the department drop-down, then we hide the <div> holding the
// classes associated with it.
if (objSelectedCat != '' && objSelectedCat != option_value) {
if (blnNS) {
if (eval(strLayerSwitch + '[\'div' + objSelectedCat + '\']')) {
eval(strLayerSwitch + '[\'div' + objSelectedCat + '\']' + strStyleSwitch + '.visibility=\'hidden\';');
}
} else if (blnGecko) {
if (eval(strLayerSwitch + '(\'div' + objSelectedCat + '\')')) {
eval(strLayerSwitch + '(\'div' + objSelectedCat + '\')' + strStyleSwitch + '.visibility = \'hidden\';');
}
} else if (blnIE || blnGecko) {
if (eval(strLayerSwitch + '[\'div' + objSelectedCat + '\']')) {
eval(strLayerSwitch + '[\'div' + objSelectedCat + '\'].className=\'categoriesHIDE\';');
}
}
}
//Set the selected department to the current value in the department drop-down
objSelectedCat = option_value;
} else { //If the department drop down value has been changed to the default '-- Select --', then we hide the previously-displayed classes
if (blnNS) {
if (eval(strLayerSwitch + '[\'div' + objSelectedCat + '\']')) {
eval(strLayerSwitch + '[\'div' + objSelectedCat + '\']' + strStyleSwitch + '.visibility=\'hidden\';');
}
} else if (blnGecko) {
if (eval(strLayerSwitch + '(\'div' + objSelectedCat + '\')')) {
eval(strLayerSwitch + '(\'div' + objSelectedCat + '\')' + strStyleSwitch + '.visibility = \'hidden\';');
}
} else if (blnIE) {
if (eval(strLayerSwitch + '[\'div' + objSelectedCat + '\']')) {
eval(strLayerSwitch + '[\'div' + objSelectedCat + '\'].className=\'categoriesHIDE\';');
}
}
//Set the selected department to nothing
objSelectedCat = '';
}
}
这个也是onchange但是没看明白。
看看这个,我以前一直用!
http://community.csdn.net/Expert/topic/3760/3760599.xml?temp=.5501367
此处是连数据库的代码我省了,你自己写$query1=mysql_query("select * from country where language_kind = '0' order by id asc");
$fMenu="";
$fValue="";
while($data1=mysql_fetch_array($query1)){
$fMenu.="\"".$data1[name]."\",";
$fValue.="\"".$data1[id]."\","; }
$fMenu=substr($fMenu,0,(strlen($fMenu)-1));
$fMenu="[".$fMenu."]";//*****************************得到var fMenu
$fValue=substr($fValue,0,(strlen($fValue)-1));
$fValue="[".$fValue."]";//*****************************得到var fValue //得到*****************************var sMenu
$query1=mysql_query("select * from country where language_kind = '0' order by id asc");
while($data1=mysql_fetch_array($query1)){
$province_id1=$data1[id]; $query2=mysql_query("select * from province where province_id='$province_id1' order by province_id desc");
while($data2=mysql_fetch_array($query2)){
$num=mysql_num_rows($query2);
$i++;
$sMenu.="\"".$data2[name]."\",";
if($i==$num){
$sMenu="[".$sMenu."],[";
$i=0;
}
}
}
$sMenu.="]";
$sMenu=str_replace("\",]","\"]",$sMenu);
$sMenu=str_replace(",[]","]",$sMenu);
if((substr($sMenu,0,2))=="[\""){
$sMenu="[".$sMenu;
}else{
$sMenu=preg_replace("/\[{3,}/is","[[\\1",$sMenu);//匹配
} //得到*****************************var sValue
$query1=mysql_query("select * from country where language_kind = '0' order by id asc");
while($data1=mysql_fetch_array($query1)){
$province_id=$data1[id]; $query2=mysql_query("select * from province where province_id='$province_id' order by province_id asc");
while($data2=mysql_fetch_array($query2)){
$nums=mysql_num_rows($query2);
$j++;
$sValue.="\"".$data2[id]."\",";
if($j==$nums){
$sValue="[".$sValue."],[";
$j=0;
}
}
}
$sValue.="]";
$sValue=str_replace("\",]","\"]",$sValue);
$sValue=str_replace(",[]","]",$sValue);
if((substr($sValue,0,2))=="[\""){
$sValue="[".$sValue;
}else{
$sValue=preg_replace("/\[{3,}/is","[[\\1",$sValue);//匹配
} ?>
<div id="tar"></div>
<SCRIPT LANGUAGE="JavaScript" DEFER>
var fMenu = <?php echo $fMenu; ?>;
var fValue = <?php echo $fValue; ?>;
var sMenu = <?php echo $sMenu; ?>;
var sValue = <?php echo $sValue; ?>; var oWhere = document.all.tar;
var ofMenu = document.createElement("<SELECT name='bigclass'>");
var osMenu = document.createElement("<SELECT name='smallclass'>");
with(oWhere)appendChild(ofMenu),appendChild(osMenu); createMainOptions();
createSubOptions(0); ofMenu.onchange = function() {createSubOptions(this.selectedIndex);}; function createMainOptions() {
for(var i=0;i<fMenu.length;i++)ofMenu.options[i] = new Option(fMenu[i],fValue[i]);
}
function createSubOptions(j) {
with(osMenu) {
length=0;
for(var i=0;i<sMenu[j].length;i++)osMenu.options[i] = new Option(sMenu[j][i],sValue[j][i]);
}
}
</SCRIPT>
<?php
/*
调用方法(说明):
将此代码保存为文件ld2.php
例如要在write.php页面放一个二级联动,则在write.php页面
要放置二级联动的地方加一句require_once("ld2.php");
若write.php要向save.php页面提交数据则在save.php中使用
$bigclass=$_POST["bigclass"];//取得大类的id值
$smallclass=$_POST["smallclass"];//取得小类的id值
接下来就知道该怎么做了吧……
附表的结构:
可能有的表的结构和我有些不同,但基本点都一样,修改程序
中对应字段和表名就ok
---------------------------------------------------------
大类的表news_bclass结构 CREATE TABLE news_bclass (
id int(11) NOT NULL auto_increment,
bname varchar(10) NOT NULL default '',
PRIMARY KEY (id),
UNIQUE KEY id_2 (id),
KEY id (id)
) TYPE=MyISAM; 字段说明:bname为大类中文名称
------------------------------ 小类的表news_sclass结构 CREATE TABLE news_sclass (
id int(11) NOT NULL auto_increment,
sname varchar(10) NOT NULL default '',
parentid int(10) NOT NULL default '0',
bname varchar(10) NOT NULL default '',
PRIMARY KEY (id),
UNIQUE KEY id_2 (id),
KEY id (id)
) TYPE=MyISAM; 字段说明:sname为小类中文名称
parendid为大类中的id值
bname为大类中文名称
-----------------------------------------------------------
*/
?>
var onecount;
onecount=0;
subcat = new Array();<?
mysql_connect("localhost","root","123456");
mysql_select_db( "test" );
$sql = "select * from menu where parent_id != 0";
$result = mysql_query( $sql );
$count = 0;
while($res = mysql_fetch_row($result)){
?>
subcat[<? echo $count; ?>] = new Array("<? echo $res[2]; ?>","<? echo $res[1]; ?>","<? echo $res[0]; ?>");
<?
$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][1] == locationid)
{
document.myform.ctype.options[document.myform.ctype.length] = new Option(subcat[i][0], subcat[i][2]);
}
}
}
</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 menu where parent_id = 0";
$result = mysql_query( $sql );
while($res = mysql_fetch_row($result)){
?>
<option value="<? echo $res[0]; ?>"><? echo $res[2]; ?></option>
<? } ?>
</select>
<select name="ctype">
<option selected value="">请指定小分类</option>
</select>
<input type="submit" name="Submit" value="搜索">
</form>CREATE TABLE `blog_type` (
`id` tinyint(4) NOT NULL auto_increment,
`parent_id` tinyint(4) NOT NULL default '0',
`name` varchar(20) default NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=14 ;#
# 导出表中的数据 `blog_type`
#INSERT INTO `blog_type` VALUES (1, 0, '人事管理');
INSERT INTO `blog_type` VALUES (2, 0, '通讯交流');
INSERT INTO `blog_type` VALUES (3, 1, '档案管理');
INSERT INTO `blog_type` VALUES (4, 1, '考勤管理');
INSERT INTO `blog_type` VALUES (5, 2, '通讯录');
INSERT INTO `blog_type` VALUES (6, 2, '网络会议');
INSERT INTO `blog_type` VALUES (7, 3, '新增档案');
INSERT INTO `blog_type` VALUES (8, 3, '查询档案');
INSERT INTO `blog_type` VALUES (9, 3, '删除档案');
INSERT INTO `blog_type` VALUES (10, 5, '新增通讯记录');
INSERT INTO `blog_type` VALUES (11, 7, '档案新增');
INSERT INTO `blog_type` VALUES (12, 0, '111111');
INSERT INTO `blog_type` VALUES (13, 12, '0000000');数据表的名字自己修改