怎么用JS控制两个DropDownList中的显示和隐藏? 5
就是当我在第一个dropdownlist中取值的时候来确定第二个dropdownlist是否显示、类似于登陆界面身份不同所需的登陆条件不同一样!!能不能来点详细的!!!只...
就是当我在第一个dropdownlist中取值的时候来确定第二个dropdownlist是否显示、类似于登陆界面 身份不同 所需的登陆条件不同 一样!! 能不能来点详细的!!! 只在前台实现 的!!
展开
3个回答
展开全部
代码如下:
<script language="javascript" type ="text/javascript" >
var Arrchange1 =new Array ();
var Arrchange2 =new Array ();
var Arrchange3 =new Array ();
function hide(s_id,index)
{
var xxx = document .getElementById (s_id);
var oldOption = xxx.children(index);
var oldStr = oldOption.innerText;
var newOption = document.createElement('<div' + oldOption.outerHTML.match(/(<\w*)([^>]*)(>)/)[2] +'>');
newOption.innerText= oldStr;
newOption.swapNode(oldOption);
//alert(xxx.innerHTML);
}
function show(s_id,index)
{
var xxx =document .getElementById (s_id);
var oldOption = xxx.children(index);
if(oldOption.tagName=='DIV')
{
var oldStr = oldOption.innerText;
var newOption = document.createElement('<option' + oldOption.outerHTML.match(/(<\w*)([^>]*)(>)/)[2] +'>');
newOption.innerText = oldStr;
newOption.swapNode(oldOption);
}
//alert(xxx.innerHTML);
}
function onchange1()
{
var s_index=document .getElementById ("Ddl_question1").options[document .getElementById ("Ddl_question1").selectedIndex].value;
s_index = parseInt(s_index);
if(s_index ==0)
{
show ('Ddl_question2',Arrchange1 [0] );
show ('Ddl_question3',Arrchange1 [0] );
Arrchange1.pop();
}
else
{
Arrchange1.push(s_index);
if(Arrchange1.length>0)
{
show ('Ddl_question2',Arrchange1 [0] );
}
if(Arrchange1.length>0)
{
show ('Ddl_question3',Arrchange1 [0] );
}
hide('Ddl_question2',s_index);
hide('Ddl_question3',s_index);
}
}
function onchange2()
{
var s_index=document .getElementById ("Ddl_question2").options[document .getElementById ("Ddl_question2").selectedIndex].value;
s_index = parseInt(s_index);
if(s_index ==0)
{
show ('Ddl_question1',Arrchange1 [0] );
show ('Ddl_question3',Arrchange3 [0] );
Arrchange2.pop();
}
else
{
Arrchange2.push(s_index);
if(Arrchange2.length>0)
{
show ('Ddl_question1',Arrchange2 [0] );
}
if(Arrchange2.length>0)
{
show ('Ddl_question3',Arrchange2 [0] );
}
hide('Ddl_question1',s_index);
hide('Ddl_question3',s_index);
}
}
function onchange3()
{
var s_index=document .getElementById ("Ddl_question3").options[document .getElementById ("Ddl_question3").selectedIndex].value;
s_index = parseInt(s_index);
if(s_index ==0)
{
show ('Ddl_question1',Arrchange3 [0] );
show ('Ddl_question2',Arrchange3 [0] );
Arrchange3.pop();
}
else
{
Arrchange3.push(s_index);
if(Arrchange1.length>0)
{
show ('Ddl_question1',Arrchange3 [0] );
}
if(Arrchange2.length>0)
{
show ('Ddl_question2',Arrchange3 [0] );
}
hide('Ddl_question1',s_index);
hide('Ddl_question2',s_index);
}
}
function a() {alert("fuck ");}
</script>
<select name="Ddl_question1" id="Ddl_question1" onchange="onchange1()">
<option value="0">请选择密保信息</option>
<option value="1">您母亲的姓名是?</option>
<option value="2">您父亲的姓名是?</option>
<option value="3">您配偶的姓名是?</option>
<option value="4">您的出生地是?</option>
<option value="5">您高中班主任的姓名是?</option>
<option value="6">您初中班主任的姓名是?</option>
<option value="7">您小学班主任的姓名是?</option>
<option value="8">您小学校名是?</option>
<option value="9">您的学号(或工号)是?</option>
<option value="10">您父亲的生日是?</option>
<option value="11">您母亲的生日是?</option>
<option value="12">您配偶的生日是?</option>
</select>
<select name="Ddl_question2" id="Ddl_question2" onchange="onchange2()">
<option value="0">请选择密保信息</option>
<option value="1">您母亲的姓名是?</option>
<option value="2">您父亲的姓名是?</option>
<option value="3">您配偶的姓名是?</option>
<option value="4">您的出生地是?</option>
<option value="5">您高中班主任的姓名是?</option>
<option value="6">您初中班主任的姓名是?</option>
<option value="7">您小学班主任的姓名是?</option>
<option value="8">您小学校名是?</option>
<option value="9">您的学号(或工号)是?</option>
<option value="10">您父亲的生日是?</option>
<option value="11">您母亲的生日是?</option>
<option value="12">您配偶的生日是?</option>
</select>
<select name="Ddl_question3" id="Ddl_question3" onchange="onchange3()">
<option value="0">请选择密保信息</option>
<option value="1">您母亲的姓名是?</option>
<option value="2">您父亲的姓名是?</option>
<option value="3">您配偶的姓名是?</option>
<option value="4">您的出生地是?</option>
<option value="5">您高中班主任的姓名是?</option>
<option value="6">您初中班主任的姓名是?</option>
<option value="7">您小学班主任的姓名是?</option>
<option value="8">您小学校名是?</option>
<option value="9">您的学号(或工号)是?</option>
<option value="10">您父亲的生日是?</option>
<option value="11">您母亲的生日是?</option>
<option value="12">您配偶的生日是?</option>
</select>
<script language="javascript" type ="text/javascript" >
var Arrchange1 =new Array ();
var Arrchange2 =new Array ();
var Arrchange3 =new Array ();
function hide(s_id,index)
{
var xxx = document .getElementById (s_id);
var oldOption = xxx.children(index);
var oldStr = oldOption.innerText;
var newOption = document.createElement('<div' + oldOption.outerHTML.match(/(<\w*)([^>]*)(>)/)[2] +'>');
newOption.innerText= oldStr;
newOption.swapNode(oldOption);
//alert(xxx.innerHTML);
}
function show(s_id,index)
{
var xxx =document .getElementById (s_id);
var oldOption = xxx.children(index);
if(oldOption.tagName=='DIV')
{
var oldStr = oldOption.innerText;
var newOption = document.createElement('<option' + oldOption.outerHTML.match(/(<\w*)([^>]*)(>)/)[2] +'>');
newOption.innerText = oldStr;
newOption.swapNode(oldOption);
}
//alert(xxx.innerHTML);
}
function onchange1()
{
var s_index=document .getElementById ("Ddl_question1").options[document .getElementById ("Ddl_question1").selectedIndex].value;
s_index = parseInt(s_index);
if(s_index ==0)
{
show ('Ddl_question2',Arrchange1 [0] );
show ('Ddl_question3',Arrchange1 [0] );
Arrchange1.pop();
}
else
{
Arrchange1.push(s_index);
if(Arrchange1.length>0)
{
show ('Ddl_question2',Arrchange1 [0] );
}
if(Arrchange1.length>0)
{
show ('Ddl_question3',Arrchange1 [0] );
}
hide('Ddl_question2',s_index);
hide('Ddl_question3',s_index);
}
}
function onchange2()
{
var s_index=document .getElementById ("Ddl_question2").options[document .getElementById ("Ddl_question2").selectedIndex].value;
s_index = parseInt(s_index);
if(s_index ==0)
{
show ('Ddl_question1',Arrchange1 [0] );
show ('Ddl_question3',Arrchange3 [0] );
Arrchange2.pop();
}
else
{
Arrchange2.push(s_index);
if(Arrchange2.length>0)
{
show ('Ddl_question1',Arrchange2 [0] );
}
if(Arrchange2.length>0)
{
show ('Ddl_question3',Arrchange2 [0] );
}
hide('Ddl_question1',s_index);
hide('Ddl_question3',s_index);
}
}
function onchange3()
{
var s_index=document .getElementById ("Ddl_question3").options[document .getElementById ("Ddl_question3").selectedIndex].value;
s_index = parseInt(s_index);
if(s_index ==0)
{
show ('Ddl_question1',Arrchange3 [0] );
show ('Ddl_question2',Arrchange3 [0] );
Arrchange3.pop();
}
else
{
Arrchange3.push(s_index);
if(Arrchange1.length>0)
{
show ('Ddl_question1',Arrchange3 [0] );
}
if(Arrchange2.length>0)
{
show ('Ddl_question2',Arrchange3 [0] );
}
hide('Ddl_question1',s_index);
hide('Ddl_question2',s_index);
}
}
function a() {alert("fuck ");}
</script>
<select name="Ddl_question1" id="Ddl_question1" onchange="onchange1()">
<option value="0">请选择密保信息</option>
<option value="1">您母亲的姓名是?</option>
<option value="2">您父亲的姓名是?</option>
<option value="3">您配偶的姓名是?</option>
<option value="4">您的出生地是?</option>
<option value="5">您高中班主任的姓名是?</option>
<option value="6">您初中班主任的姓名是?</option>
<option value="7">您小学班主任的姓名是?</option>
<option value="8">您小学校名是?</option>
<option value="9">您的学号(或工号)是?</option>
<option value="10">您父亲的生日是?</option>
<option value="11">您母亲的生日是?</option>
<option value="12">您配偶的生日是?</option>
</select>
<select name="Ddl_question2" id="Ddl_question2" onchange="onchange2()">
<option value="0">请选择密保信息</option>
<option value="1">您母亲的姓名是?</option>
<option value="2">您父亲的姓名是?</option>
<option value="3">您配偶的姓名是?</option>
<option value="4">您的出生地是?</option>
<option value="5">您高中班主任的姓名是?</option>
<option value="6">您初中班主任的姓名是?</option>
<option value="7">您小学班主任的姓名是?</option>
<option value="8">您小学校名是?</option>
<option value="9">您的学号(或工号)是?</option>
<option value="10">您父亲的生日是?</option>
<option value="11">您母亲的生日是?</option>
<option value="12">您配偶的生日是?</option>
</select>
<select name="Ddl_question3" id="Ddl_question3" onchange="onchange3()">
<option value="0">请选择密保信息</option>
<option value="1">您母亲的姓名是?</option>
<option value="2">您父亲的姓名是?</option>
<option value="3">您配偶的姓名是?</option>
<option value="4">您的出生地是?</option>
<option value="5">您高中班主任的姓名是?</option>
<option value="6">您初中班主任的姓名是?</option>
<option value="7">您小学班主任的姓名是?</option>
<option value="8">您小学校名是?</option>
<option value="9">您的学号(或工号)是?</option>
<option value="10">您父亲的生日是?</option>
<option value="11">您母亲的生日是?</option>
<option value="12">您配偶的生日是?</option>
</select>
展开全部
document.getElementById("ddl1").display="none";//隐藏
document.getElementById("ddl2").display="block";//显示
document.getElementById("ddl2").display="block";//显示
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
首先,建议你先百度下jquery的选择器,是可以同时选择这俩控件的,关于显示和隐藏实现问题具体你自己操作。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询