在当前页面加一个根据name="post_manage"的select的值初始化name='post_child_manage'>的函数,如
function InitSelected2(post_manage_value)
{}然后在返回时向页面输出一段js代码,然后调用这个函数dim script
dim post_manage:post_manage=request("post_manage")
'其他代码
script=script&"<script>"
'注意是在window.onload中,要不可能出现找不到对象的js错误
script=script&"<window.onload=function(){InitSelected2('"&post_manage&"')}"
script=script&"<</script>"response.write script'输出脚本
function InitSelected2(post_manage_value)
{}然后在返回时向页面输出一段js代码,然后调用这个函数dim script
dim post_manage:post_manage=request("post_manage")
'其他代码
script=script&"<script>"
'注意是在window.onload中,要不可能出现找不到对象的js错误
script=script&"<window.onload=function(){InitSelected2('"&post_manage&"')}"
script=script&"<</script>"response.write script'输出脚本
解决方案 »
- 动态添加JS到html
- 求正则表达式 " <script>alert("发送成功");window.close();</script>" 取出alert内的内容
- badapple-js版..散分
- 带有下拉框的搜索框如何做?
- 初学者问题---紧急,在线急等
- 如何获得input控件的left,top,width,height
- 看看是否有错,请过管理员
- 急啊,高手请教:如何在body onload事件中设定窗口的属性
- 一个新的问题,真的很新的问题。就如何改<input type="text" name="www-www" value="welcome">的值。
- 如何从text框中判断输入的是字符还是数字?
- 请高手帮助:如何移动FLASH标题的位置?
- HTC中 element.parentNode.removeChild(element)自己删除自己
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=gb2312"/>
<title>Test</title>
</head>
<script>
function post_class_List()
{
this.length=3; //长度只有3,你定义10干吗???怪不的你添加select的options时使用try{}catch{}语句。
this[0]=new Option("请选择","0");
this[1]=new Option("经营管理类","1000");
this[2]=new Option("销售类","1100");
return this;
}
function post_class_child_List()
{
//===============定义2级菜单时,使用1级菜单的option的value来做索引===============
this.length=3; //长度只有3,你定义10干吗???怪不的你添加select的options时使用try{}catch{}语句。
this[0]=new Array(1);
this[0][0]=new Option("请选择","0");
this[1000]=new Array(13);
this[1000][0]=new Option("首席执行官CEO/总裁/总经理","1001");
this[1000][1]=new Option("首席运营官COO","1002");
this[1000][2]=new Option("首席技术官CTO/首席信息官CIO","1003");
this[1000][3]=new Option("首席财务官CFO","1004");
this[1000][4]=new Option("副总裁/副总经理","1005");
this[1000][5]=new Option("合伙人","1006");
this[1000][6]=new Option("总监/事业部总经理","1007");
this[1000][7]=new Option("总裁助理/总经理助理","1008");
this[1000][8]=new Option("分公司经理/分支机构经理/办事处经理","1009");
this[1000][9]=new Option("部门经理/厂长/副厂长/店长","1010");
this[1000][10]=new Option("生产经理/车间主任","1011");
this[1000][11]=new Option("组长/班长","1012");
this[1000][12]=new Option("其它职位(经营管理类)","1013"); this[1100]=new Array(10);
this[1100][0]=new Option("销售总监","1101");
this[1100][1]=new Option("销售经理/销售主管","1102");
this[1100][2]=new Option("渠道总监/分销总监","1103");
this[1100][3]=new Option("渠道分销经理/渠道分销主管","1104");
this[1100][4]=new Option("售前支持经理/售前支持主管","1105");
this[1100][5]=new Option("销售助理","1106");
this[1100][6]=new Option("商务经理/商务主管","1107");
this[1100][7]=new Option("商务专员/商务助理","1108");
this[1100][8]=new Option("业务拓展(BD)经理","1109");
this[1100][9]=new Option("其它职位(销售类)","1110"); return this;
}
var postTop=new post_class_List();
var postSec=new post_class_child_List();function Init(TopId)
{
var pt=document.getElementById("post_manage");
for(var i=0;i<postTop.length;i++)
{
pt.options.add(postTop[i]);
}
if(TopId.toLowerCase()=="first")
{
Hanlder(0);
}
else if(!isNaN(TopId))
{
for( var j=0;j<pt.options.length;j++)
{
if(pt.options[j].value==TopId)
{
pt.options[j].selected=true;
break;
}
}
Hanlder(parseInt(TopId,10));
}
else
{
alert("参数错误!");
}
}function Hanlder(v)
{
var child=document.getElementById("post_child_manage");
child.options.length=0;
for(var i=0;i<postSec[v].length;i++)
{
child.options.add(postSec[v][i]);
}
}
</script>
<body>
<form method="post" action="">
<select class="input" id="post_manage" onchange="Hanlder(parseInt(this.value))" name="post_manage">
</select>
<select class="input" name='post_child_manage' id="post_child_manage">
</select>
<br />
<input type="submit" value="提交" />
<script language="JavaScript" type="text/javascript">
<%
dim pm:pm=request.form("post_manage")&""
if pm="" then '第一次初始化
response.write "window.onload=function(){Init('first','');}"
else
response.write "window.onload=function(){Init('"&pm&"');}"
end if
%>
</script>
</form></body>
</html>
我测试了你的程序,还有几个问题想请教下,Init('first','');}"这个传值过去,这是两个值吧,用一个TopId能接收么?
TopId.toLowerCase()=="first" 【'first',''】和【first】判断能相等么?第二个问题是,返回的结果,post_child_manage的值默认为第一个,我想这个也可以通过
Init(‘first’,"")pcm=request.form("post_child_manage")&""
Init('"&pm&"','"&pcm&"')
传值过去解决吧?第三个问题是,返回值的保存问题,如果我第一次ACTION="",提交后,状态是可以保存的(post_child_manage的值默认为第一个),第二次修改ACTION指向另外个页面,再提交,返回后状态还是可以保存的(post_child_manage的值默认为第一个);但如果我第一次ACTION直接指向另外个页面,返回后状态就无法保存。再次感谢你的帮助
第一个问题是笔误,没有第2个参数的.不过也可以传递多个参数,不过在函数名()中没定义的变量需要在函数体中使用argumenets对象
看下面的例子
function a(v)
{
alert("参数个数:"+arguments.length+"\n"+"变量v="+v+"\n最后一个参数的值:"+argumenets[arguments.length-1]);
}
a(1);
a(1,2,3);
a(1);
a(4,2,3,4);2.
你提交时根据你选择的值来初始化,不过你得改Init函数.在使用Init初始化post_manage后再调用Hanlder来初始化post_child_manage,给个思路给你,自己改代码成功后印象更深3.
你在另一个页面返回提交页面时可以把选择的post_manage和post_child_manage的值通过url传递过来,然后根据传递的值来初始化就可以了,不过获取值时不再是request.form了,而是request.querystirng,不过你可以改为通用的request来代替.
function a(v)
{
alert("参数个数:"+arguments.length+"\n"+"变量v="+v+"\n最后一个参数的值:"+arguments[arguments.length-1]);
}
a();
a(1,2,3);
a(1);
a(4,2,3,4);
在普通的环境下,这个问题算是解决了;我引用的环境比较的复杂,同一个页面要调用多次,有不同的页面调用该函数;而该函数又封装在ASP 的 FUNCTION里面,
所以如果在每个提交的页面处理这个问题肯定非常的麻烦,提交后返回上一步,我用的是javascript:history.go(-1),如果直接地址访问,又有很多内容丢失。用COOKIES存储,POST_CHILD_MANAGE的值得又没办法写入。所以还想请教你有没有更好的方法解决这个问题,如果没有,只有在下一个页面,获取了POST_CHILD_MANAGE直接写入COOKIES。
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=gb2312"/>
<title>Test</title>
</head>
<script>
function post_class_List()
{
this.length=3;
this[0] = new Option("请选择","0");
this[1] = new Option("经营管理类","1000");
this[2] = new Option("销售类","1100");
return this;
}
function post_class_child_List()
{
//===============定义2级菜单时,使用1级菜单的option的value来做索引===============
this.length=3;
this[0]=new Array(1);
this[0][0]=new Option("请选择","0");
this[1000]=new Array(13);
this[1000][0]=new Option("首席执行官CEO/总裁/总经理","1001");
this[1000][1]=new Option("首席运营官COO","1002");
this[1000][2]=new Option("首席技术官CTO/首席信息官CIO","1003");
this[1000][3]=new Option("首席财务官CFO","1004");
this[1000][4]=new Option("副总裁/副总经理","1005");
this[1000][5]=new Option("合伙人","1006");
this[1000][6]=new Option("总监/事业部总经理","1007");
this[1000][7]=new Option("总裁助理/总经理助理","1008");
this[1000][8]=new Option("分公司经理/分支机构经理/办事处经理","1009");
this[1000][9]=new Option("部门经理/厂长/副厂长/店长","1010");
this[1000][10]=new Option("生产经理/车间主任","1011");
this[1000][11]=new Option("组长/班长","1012");
this[1000][12]=new Option("其它职位(经营管理类)","1013");
this[1100]=new Array(10);
this[1100][0]=new Option("销售总监","1101");
this[1100][1]=new Option("销售经理/销售主管","1102");
this[1100][2]=new Option("渠道总监/分销总监","1103");
this[1100][3]=new Option("渠道分销经理/渠道分销主管","1104");
this[1100][4]=new Option("售前支持经理/售前支持主管","1105");
this[1100][5]=new Option("销售助理","1106");
this[1100][6]=new Option("商务经理/商务主管","1107");
this[1100][7]=new Option("商务专员/商务助理","1108");
this[1100][8]=new Option("业务拓展(BD)经理","1109");
this[1100][9]=new Option("其它职位(销售类)","1110");
return this;
}
var postTop=new post_class_List();
var postSec=new post_class_child_List();function Init(Id)
{
TopId=arguments[0];
SecId=arguments[1];
var pt=document.getElementById("post_manage");
for(var i=0;i<postTop.length;i++)
{
pt.options.add(postTop[i]);
}
if(TopId.toLowerCase()=="first")
{
Hanlder(0,"");
}
else if(!isNaN(TopId))
{
for( var j=0;j<pt.options.length;j++)
{
if(pt.options[j].value==TopId)
{
pt.options[j].selected=true;
break;
}
}
Hanlder(parseInt(TopId,10),SecId);
}
else
{
alert("参数错误!");
}
}function Hanlder(c)
{
v=arguments[0];
x=arguments[1];
var child=document.getElementById("post_child_manage");
child.options.length=0;
for(var i=0;i<postSec[v].length;i++)
{
child.options.add(postSec[v][i]);
}
if(x!=="")
{
for( var j=0;j<child.options.length;j++)
{
if(child.options[j].value==x)
{
child.options[j].selected=true;
break;
}
}
}
//setCookie("post_manage",v)
//setCookie("post_child_manage",x)
}
function setCookie(name,value)
{
var Days = 1; //此 cookie 将被保存 30 天
var exp = new Date(); //new Date("December 31, 9998");
exp.setTime(exp.getTime() + Days*24*60*60*1000);
document.cookie = name + "="+ escape(value) +";expires="+ exp.toGMTString();
}
</script>
<body>
<form method="post" action="test2.asp">
<select class="input" id="post_manage" onchange="Hanlder(parseInt(this.value))" name="post_manage"></select>
<select class="input" name='post_child_manage' id="post_child_manage"></select>
<input type="submit" value="提交" />
<script language="JavaScript" type="text/javascript">
<%
dim pm:pm=request.form("post_manage")&""
dim pcm:pcm=request.form("post_child_manage")&""
if pm="" then '第一次初始化
response.write "window.onload=function(){Init('first','');}"
else
response.write "window.onload=function(){Init('"&pm&"','"&pcm&"');}"
end if
%>
</script>
</form></body>
</html>
一直没等到showbo的建议,比较遗憾;总的来说,还是非常感谢你,你的程序开拓了我的思路,可以在此基础上做进一步的修改(写的水平不怎么样,修改别人的东西还是非常强悍的 :) )。