例:
产品名称 产品型号(如果选1则是产品1的型号,选2则是产品2的型号)
产品1
产品2
产品3
请问如何实现.而其他控制的值.又不变.
用
<select>
<option value="1">产品1</option>
<option value="2">产品2</option>
<option value="3">产品3</option>
</select>
方法一:
SCRIPT LANGUAGE="JavaScript">
<!--
function Dsy()
{
this.Items = {};
}
Dsy.prototype.add = function(id,iArray)
{
this.Items[id] = iArray;
}
Dsy.prototype.Exists = function(id)
{
if(typeof(this.Items[id]) == "undefined") return false;
return true;
}
function change(v){
var str="0";
for(i=0;i<v;i++){ str+=("_"+(document.getElementById(s[i]).selectedIndex-1));};
var ss=document.getElementById(s[v]);
with(ss){
length = 0;
options[0]=new Option(opt0[v],opt0[v]);
if(v && document.getElementById(s[v-1]).selectedIndex>0 || !v)
{
if(dsy.Exists(str)){
ar = dsy.Items[str];
for(i=0;i<ar.length;i++)options[length]=new Option(ar[i],ar[i]);
if(v)options[1].selected = true;
}
}
if(++v<s.length){change(v);}
}
}
var dsy = new Dsy();
dsy.add("0",["产品1","产品2","产品3"]);
//第二层
//产品1
dsy.add("0_0",["产品1型号A","产品1型号B"]);
//产品2
dsy.add("0_1",["产品2型号A","产品2型号B"]);
//产品3
dsy.add("0_2",["产品3型号A","产品3型号B"]);
//第三层
dsy.add("0_0_0",["..."]);
dsy.add("0_0_1",["..."]);
dsy.add("0_1_0",["..."]);
dsy.add("0_1_1",["..."]);
dsy.add("0_2_0",["..."]);
dsy.add("0_2_1",["..."]);
//-->
</SCRIPT>
<SCRIPT LANGUAGE = JavaScript>
<!--
var s=["s1","s2","s3"];
var opt0 = ["产品名称","产品型号","产品其他"];
function setup()
{
for(i=0;i<s.length-1;i++)
document.getElementById(s[i]).onchange=new Function("change("+(i+1)+")");
change(0);
}
//-->
</SCRIPT>
<select name="cpmc" id="s1">
<option>产品名称</option></select>
<select name="cpxh" id="s2">
<option>产品型号</option></select>
<select name="cpqt" id="s3">
<option>产品其他</option></select>
方法二:
<script language="JavaScript" >
function make_fjgse_menu(fjgsc_value,fjgse_X)
{
var sql = "select * from fjgse where fjgsc='"+fjgsc_value+"'" ;
var ConnDB = new ActiveXObject("adodb.connection");
var rs = new ActiveXObject("ADODB.Recordset");
ConnDB.ConnectionString="DSN=data;uid=data;pwd=data";
ConnDB.open
rs.open(sql,ConnDB,1,1);
if(rs.recordcount!=0)
{
var count=1;
fjgse_X.options[0]=new Option("--请选择发件公司名称(英文)--"," ");
while(!rs.eof)
{
fjgse_X.options[count]=new Option(rs("fjgse"),rs("fjgse"));
count=count+1;
rs.movenext
}
var sql=null;
rs.close
ConnDB.close
fjgse_X.options[0].selected=true;
fjgse_X.length=count;
}
else
{
fjgse_X.options[0]=new Option("--请选择发件公司名称(英文)--"," ");
var sql=null;
rs.close
ConnDB.close
fjgse_X.options[0].selected=true;
fjgse_X.length=1;
}
}
function checkform()
{
var subst = document. input_form;
if (subst.fjgsc.value=="")
{
alert("DHL发件公司名称(中文)不能为空!!");
subst.fjgsc.focus();
return false;
}
if (subst.fjgse.value=="")
{
alert("DHL发件公司名称(英文)不能为空!!");
subst.fjgse.focus();
return false;
}
if (subst.fjr.value=="")
{
alert("发件人姓名不能为空!");
subst.fjr.focus();
return false;
}
return true;
}
function SureDelSingle(id)
{
if ( confirm("您确定要删除该发件人信息吗?"))
{
window.location.href = "fajianren.asp?method=del&id=" +id;
}
}
</script>
[此贴子已经被作者于2007-7-11 18:39:03编辑过]
[CODE]SCRIPT LANGUAGE="JavaScript">
<!--
function Dsy()
{
this.Items = {};
}
Dsy.prototype.add = function(id,iArray)
{
this.Items[id] = iArray;
}
Dsy.prototype.Exists = function(id)
{
if(typeof(this.Items[id]) == "undefined") return false;
return true;
}
function change(v){
var str="0";
for(i=0;i<v;i++){ str+=("_"+(document.getElementById(s[i]).selectedIndex-1));};
var ss=document.getElementById(s[v]);
with(ss){
length = 0;
options[0]=new Option(opt0[v],opt0[v]);
if(v && document.getElementById(s[v-1]).selectedIndex>0 || !v)
{
if(dsy.Exists(str)){
ar = dsy.Items[str];
for(i=0;i<ar.length;i++)options[length]=new Option(ar[i],ar[i]);
if(v)options[1].selected = true;
}
}
if(++v<s.length){change(v);}
}
}
var dsy = new Dsy();
dsy.add("0",["产品1","产品2","产品3"]);
//第二层
//产品1
dsy.add("0_0",["产品1型号A","产品1型号B"]);
//产品2
dsy.add("0_1",["产品2型号A","产品2型号B"]);
//产品3
dsy.add("0_2",["产品3型号A","产品3型号B"]);
//第三层
dsy.add("0_0_0",["..."]);
dsy.add("0_0_1",["..."]);
dsy.add("0_1_0",["..."]);
dsy.add("0_1_1",["..."]);
dsy.add("0_2_0",["..."]);
dsy.add("0_2_1",["..."]);
//-->
</SCRIPT>
<SCRIPT LANGUAGE = JavaScript>
<!--
var s=["s1","s2","s3"];
var opt0 = ["产品名称","产品型号","产品其他"];
function setup()
{
for(i=0;i<s.length-1;i++)
document.getElementById(s[i]).onchange=new Function("change("+(i+1)+")");
change(0);
}
//-->
</SCRIPT>
<select name="cpmc" id="s1">
<option>产品名称</option></select>
<select name="cpxh" id="s2">
<option>产品型号</option></select>
<select name="cpqt" id="s3">
<option>产品其他</option></select>[/CODE]