2008-04-01
XSL通过javascript的三级联动
今天搞了个xsl三级联动 ,有需要的朋友可以看看。
先看看java代码
//所有单位
List companyNameList = this.trainQuery.queryCompany();//查询所有机构
for(int i = 0; i< companyNameList.size(); i++) { //循环编历机构集合
Element usersXML = enterType.addElement("option1");
// 输出单位节点
Company company = (Company) companyNameList.get(i);
usersXML.addAttribute("id", company.getId().getCompanyId().toString());//机构id
usersXML.addAttribute("name", company.getId().getCompanyName());//机构名称
// 通过单位的id得到部门信息
List departmentList = this.systemQuery.searchDepartmentList(company.getId().getCompanyId()); //全部部门
for (int j = 0; j < departmentList.size(); j++) {
// 循环输出部门信息节点
Element userXML2 = usersXML.addElement("option2");
Department department= (Department) departmentList.get(j);
if (department.getId().getDepartmentId() != null) {
Element usersXML4 = enterType.addElement("option2");
// 将部门信息输出在一级节点之下
userXML2.addAttribute("id", department.getId().getDepartmentId().toString());
userXML2.addAttribute("name", department.getId().getDepartmentName().toString());
// 输出平级的节点
usersXML4.addAttribute("id", department.getId().getDepartmentId().toString());
usersXML4.addAttribute("name", department.getId().getDepartmentName().toString());
// 通过单位,部门得到岗位信息
List postionlist =
this.hiringQuery.queryPositionRegBycid(company.getId().getCompanyId().toString(), department.getId().getDepartmentId().toString());
// 循环输出节点
for(int k=0;k<postionlist.size();k++){
Element userXML3 = usersXML4.addElement("option3");
PositionReg positionReg = (PositionReg) postionlist.get(i);
if(positionReg!=null){
userXML3.addAttribute("id", positionReg.getPositionId());
userXML3.addAttribute("name", positionReg.getPositionName());
// 编辑回显节点
Element selectfirstlevel = postionId.addElement("selectfirstlevel");
selectfirstlevel.addAttribute("firstlevelcode", company.getId().getCompanyId().toString());
selectfirstlevel.addAttribute("secondlevelcode",department.getId().getDepartmentId().toString());
Element selectsecondlevel = postionId.addElement("selectsecondlevel");
selectsecondlevel.addAttribute("secondonelevelcode", department.getId().getDepartmentId().toString());
selectsecondlevel.addAttribute("thirdlevelcode", positionReg.getPositionId());
}
}
}
}
}
用xsl做有点繁琐,我都累了。
看看输出节点形式:
<position_name_list>
<enterType>
<option1 id="1" name="西安曲江文化产业投资(集团)有限公司">
<option2 id="16" name="财务部"/>
<option2 id="17" name="旅游部"/>
<option2 id="18" name="市场部"/>
</option1>
<option2 id="16" name="财务部"/>
<option2 id="17" name="旅游部"/>
<option2 id="18" name="市场部">
<option3 id="dd92998aff9e11dc8f3dcf619afba614" name="asd"/>
</option2>
<option1 id="2" name="西安曲江文化旅游(集团)有限公司"/>
<option1 id="3" name="西安曲江大雁塔景区管理服务有限公司"/>
<option1 id="4" name="西安曲江大雁塔景区资产运营管理有限公司"/>
<option1 id="5" name="西安曲江影视投资(集团)有限公司"/>
<option1 id="6" name="西安曲江国际会展(集团)有限公司"/>
<option1 id="7" name="西安曲江国际会展投资控股有限公司"/>
<option1 id="8" name="西安曲江大唐不夜城文化商业有限公司"/>
<option1 id="9" name="西安曲江建设集团有限公司"/>
<option1 id="10" name="西安曲江文化演出(集团)有限公司"/>
<option1 id="11" name="唐华宾馆有限公司"/>
<option1 id="12" name="西安曲江欢乐世界有限公司"/>
<option1 id="13" name="陕西法门寺文化景区建设有限公司"/>
<option1 id="14" name="西安曲江职业围棋俱乐部有限公司"/>
</enterType>
<postionId>
<selectfirstlevel firstlevelcode="1" secondlevelcode="18"/>
<selectsecondlevel secondonelevelcode="18" thirdlevelcode="dd92998aff9e11dc8f3dcf619afba614"/>
</postionId>
</position_name_list>
最后看看页面:
<?xml version="1.0" encoding="GB2312"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="GB2312" indent="no" />
<xsl:template match="root">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>更新岗位信息</title>
<link href="../../css/css.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<table width="98%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr class="trtop1">
<td height="30" class="wenzi1">岗位信息管理</td>
</tr>
</table>
<form action="QJ060204Action.do" method="post" name="position_name_listForm">
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="12" height="26" class="tdtleftbg"> </td>
<th class="tdtdline">更新岗位信息</th>
<td width="12" class="tdtrightbg"> </td>
</tr>
</table>
</td>
</tr>
<tr>
<td><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="tbbg1">
<tr>
<td valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0" class="wenzi3">
<tbody>
<input name="recruit_position_id" type="hidden" value="{recruit_position/recruit_position_id}"></input>
<tr>
<td width="15%" align="left" class="trbg1">岗位所属机构:</td>
<td width="85%" align="left" class="trbg1">
<select name="companyId" onChange="selectfirstlevel('companyId','deptmentId','position_name_listForm');">
<option value="0" >请选择--</option>
</select>
</td>
</tr>
<tr>
<td width="15%" align="left" class="trbg1">岗位所属部门:</td>
<td width="15%" align="left" class="trbg1">
<select name="deptmentId" onChange="selectsecond('deptmentId','postionId','position_name_listForm');">
<option value="0" >请选择--</option>
</select>
</td>
</tr>
<tr>
<td width="15%" align="left" class="trbg1">岗位名称:</td>
<td width="15%" align="left" class="trbg1">
<select name="postionId">
<option value="0" >请选择--</option>
</select>
<script language="javascript">
firstlevel("companyId","deptmentId","position_name_listForm","<xsl:value-of select="position_name_list/postionId/selectfirstlevel/@firstlevelcode"/>","<xsl:value-of select="position_name_list/postionId/selectfirstlevel/@secondlevelcode"/>");
secondlevel("deptmentId","postionId","position_name_listForm","<xsl:value-of select="position_name_list/postionId/selectsecondlevel/@secondonelevelcode"/>","<xsl:value-of select="position_name_list/postionId/selectsecondlevel/@thirdlevelcode"/>");
</script>
</td>
</tr>
<tr>
<td align="left" class="trbg1">岗位编号:</td>
<td align="left" class="trbg1">
<input type="text" name="recruit_position_code">
<xsl:attribute name="value">
<xsl:value-of select="recruit_position/recruit_position_code"/>
</xsl:attribute>
</input>
</td>
</tr>
<!--tr>
<td align="left" class="trbg1">岗位所属机构:</td>
<td align="left" class="trbg1"><label>
<select name="position_of_org" class="wenzi3">
<xsl:for-each select="recruit_position/positionOrgList/position_of_org">
<xsl:if test="CODE/@selected[.='1']">
<option selected='selected'>
<xsl:attribute name="value">
<xsl:value-of select="company_id"/>
</xsl:attribute>
<xsl:value-of select="NAME"/>
</option>
</xsl:if>
<xsl:if test="CODE/@selected[.='0']">
<option>
<xsl:attribute name="value">
<xsl:value-of select="company_id"/>
</xsl:attribute>
<xsl:value-of select="NAME"/>
</option>
</xsl:if>
</xsl:for-each>
</select>
</label>
</td>
</tr-->
<tr>
<td align="left" class="trbg1"><p>是否发布:</p></td>
<td align="left" class="trbg1"><label>
<input type="radio" name="state" value="1">
<xsl:if test="recruit_position/state[.='1']">
<xsl:attribute name="checked">checked</xsl:attribute>
</xsl:if>
</input>
发布
<input type="radio" name="state" value="0">
<xsl:if test="recruit_position/state[.='0']">
<xsl:attribute name="checked">checked</xsl:attribute>
</xsl:if>
<xsl:attribute name="value">
<xsl:value-of select="recruit_position/state"/>
</xsl:attribute>
</input>
不发布 </label>
</td>
</tr>
<tr>
<!-- 岗位性质 :0:全职,1:兼职,2: 临时,3:实习; -->
<td align="left" class="trbg1">岗位性质:</td>
<td align="left" class="trbg1"><label>
<input type="radio" name="position_property" value="1">
<xsl:if test="recruit_position/position_property[.='1']">
<xsl:attribute name="checked">checked</xsl:attribute>
</xsl:if>
</input>
全职
<input type="radio" name="position_property" value="2">
<xsl:if test="recruit_position/position_property[.='2']">
<xsl:attribute name="checked">checked</xsl:attribute>
</xsl:if>
</input>
兼职
<input type="radio" name="position_property" value="3">
<xsl:if test="recruit_position/position_property[.='3']">
<xsl:attribute name="checked">checked</xsl:attribute>
</xsl:if>
</input>
临时
<input type="radio" name="position_property" value="4">
<xsl:if test="recruit_position/position_property[.='4']">
<xsl:attribute name="checked">checked</xsl:attribute>
</xsl:if>
</input>
实习 </label></td>
</tr>
<tr>
<td align="left" class="trbg1">岗位有效期:</td>
<td align="left" class="trbg1">
<input type="text" name="from_date" onFocus="new WdatePicker(this,'%Y-%M-%D',false,'whyGreen')">
<xsl:attribute name="value"><xsl:value-of select="recruit_position/from_date"/></xsl:attribute>
</input>
至
<input type="text" name="thru_date" onFocus="new WdatePicker(this,'%Y-%M-%D',false,'whyGreen')">
<xsl:attribute name="value"><xsl:value-of select="recruit_position/thru_date"/></xsl:attribute>
</input>
</td>
</tr>
<tr>
<td align="left" class="trbg1">招聘人数:</td>
<td align="left" class="trbg1">
<input type="text" name="request_amount">
<xsl:attribute name="value"><xsl:value-of select="recruit_position/request_amount"/></xsl:attribute>
</input>
人</td>
</tr>
<tr>
<!-- 工作年限 1:不限,2:一年,3:两年,4:三年,5:四年,6:五年以上 -->
<td align="left" class="trbg1">工作年限:</td>
<td align="left" class="trbg1">
<select name="work_experience_year">
<xsl:for-each select="recruit_position/workExperienceYearList/work_experience_year">
<xsl:if test="CODE/@selected[.='1']">
<option selected='selected'>
<xsl:attribute name="value">
<xsl:value-of select="dict_code"/>
</xsl:attribute>
<xsl:value-of select="NAME"/>
</option>
</xsl:if>
<xsl:if test="CODE/@selected[.='0']">
<option>
<xsl:attribute name="value">
<xsl:value-of select="dict_code"/>
</xsl:attribute>
<xsl:value-of select="NAME"/>
</option>
</xsl:if>
</xsl:for-each>
</select></td>
</tr>
<tr>
<td align="left" class="trbg1">语言要求:</td>
<td align="left" class="trbg1">
<input type="text" name="foreign_language">
<xsl:attribute name="value">
<xsl:value-of select="recruit_position/foreign_language"/>
</xsl:attribute>
</input>
</td>
</tr>
<tr>
<td align="left" class="trbg1">学历要求:</td>
<td align="left" class="trbg1">
<input type="text" name="diploma">
<xsl:attribute name="value">
<xsl:value-of select="recruit_position/diploma"/>
</xsl:attribute>
</input>
</td>
</tr>
<tr>
<td align="left" class="trbg1">岗位描述及要求:</td>
<td align="left" class="trbg1"><label>
<textarea name="responsibility_describe">
<xsl:value-of select="recruit_position/responsibility_describe"/>
</textarea>
</label></td>
</tr>
<tr>
<td colspan="2" align="center" class="trbg1"><input name="Submit22" value="保存" type="submit"/>
<input name="重置" value="重置" type="reset"/></td>
</tr>
</tbody>
</table></td>
</tr>
</table></td>
</tr>
<tr>
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="12" height="26" class="tddleftbg"> </td>
<td class="tdtdline"> </td>
<td width="12" class="tddrightbg"> </td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
其中这两句是进行数据回显的
<script language="javascript">
firstlevel("companyId","deptmentId","position_name_listForm","<xsl:value-of select="position_name_list/postionId/selectfirstlevel/@firstlevelcode"/>","<xsl:value-of select="position_name_list/postionId/selectfirstlevel/@secondlevelcode"/>");
secondlevel("deptmentId","postionId","position_name_listForm","<xsl:value-of select="position_name_list/postionId/selectsecondlevel/@secondonelevelcode"/>","<xsl:value-of select="position_name_list/postionId/selectsecondlevel/@thirdlevelcode"/>");
</script>最后看看javascript
<!-- 企业性质javascript 开始 -->
<script type="text/javascript">
firstlevelcode=new Array(<xsl:value-of select="count(position_name_list/enterType/option1)"/>)
secondlevelname=new Array(<xsl:value-of select="count(position_name_list/enterType/option1)"/>);
secondlevelcode=new Array(<xsl:value-of select="count(position_name_list/enterType/option1)"/>);
function firstlevel(preP,preC,formname,selectP,selectC)
{
a=0;
<xsl:for-each select="position_name_list/enterType/option1">
if (selectP=='<xsl:value-of select="@id"/>')
{ a=<xsl:value-of select="position()"/>;tempoption=new Option('<xsl:value-of
select="@name"/>','<xsl:value-of select="@id"/>',false,true); }
else
{ tempoption=new Option('<xsl:value-of select="@name"/>','<xsl:value-of select="@id"/>'); }
eval('document.'+formname+'.'+preP+'.options[<xsl:value-of select="position()"/>]=tempoption;');
thissecondlevelcode = new Array(<xsl:value-of select="count(option2)"/>);
thissecondlevelname = new Array(<xsl:value-of select="count(option2)"/>);
<xsl:for-each select="option2">
thissecondlevelcode[<xsl:value-of select="position()-1"/>]='<xsl:value-of select="@id"/>';
thissecondlevelname[<xsl:value-of select="position()-1"/>]='<xsl:value-of select="@name"/>';
</xsl:for-each>
firstlevelcode[<xsl:value-of select="position()-1"/>]='<xsl:value-of select="@id"/>';
secondlevelcode[<xsl:value-of select="position()-1"/>]=thissecondlevelcode;
secondlevelname[<xsl:value-of select="position()-1"/>]=thissecondlevelname;
</xsl:for-each>
<![CDATA[
eval('document.'+formname+'.'+preP+'.options[a].selected=true;');
b=0;
if (selectC!='0' )
{
b=1;
for (i=0;i<firstlevelcode.length;i++)
{
if (selectP==firstlevelcode[i])
{
b=i+1;
break;
}
}
cityid=b;
b=0;
for (i=0;i<secondlevelname[cityid-1].length;i++)
{
if (selectC==secondlevelcode[cityid-1][i])
{b=i+1;tempoption=new Option(secondlevelname[cityid-1][i],secondlevelcode[cityid-1][i],false,true);}
else
tempoption=new Option(secondlevelname[cityid-1][i],secondlevelcode[cityid-1][i]);
eval('document.'+formname+'.'+preC+'.options[i+1]=tempoption;');
}
eval('document.'+formname+'.'+preC+'.options[b].selected=true;');
}
}
function selectfirstlevel(preP,preC,formname)
{
cityid=eval('document.'+formname+'.'+preP+'.selectedIndex;');
j=eval('document.'+formname+'.'+preC+'.length;');
for (i=1;i<j;i++)
{eval('document.'+formname+'.'+preC+'.options[j-i]=null;')}
if (cityid!="0")
{
for (i=0;i<secondlevelname[cityid-1].length;i++)
{
tempoption=new Option(secondlevelname[cityid-1][i],secondlevelcode[cityid-1][i]);
eval('document.'+formname+'.'+preC+'.options[i+1]=tempoption;');
}
}
}
]]>
</script>
<script type="text/javascript">
secondonelevelcode=new Array(<xsl:value-of select="count(position_name_list/enterType/option2)"/>)
thirdlevelname=new Array(<xsl:value-of select="count(position_name_list/enterType/option2)"/>);
thirdlevelcode=new Array(<xsl:value-of select="count(position_name_list/enterType/option2)"/>);
function secondlevel(preP,preC,formname,selectP,selectC)
{
a=0;
<xsl:for-each select="position_name_list/enterType/option2">
if (selectP=='<xsl:value-of select="@id"/>')
{ a=<xsl:value-of select="position()"/>;tempoption=new Option('<xsl:value-of
select="@name"/>','<xsl:value-of select="@id"/>',false,true); }
else
{ tempoption=new Option('<xsl:value-of select="@name"/>','<xsl:value-of select="@id"/>'); }
eval('document.'+formname+'.'+preP+'.options[<xsl:value-of select="position()"/>]=tempoption;');
thisthirdlevelcode = new Array(<xsl:value-of select="count(option3)"/>);
thisthirdlevelname = new Array(<xsl:value-of select="count(option3)"/>);
<xsl:for-each select="option3">
thisthirdlevelcode[<xsl:value-of select="position()-1"/>]='<xsl:value-of select="@id"/>';
thisthirdlevelname[<xsl:value-of select="position()-1"/>]='<xsl:value-of select="@name"/>';
</xsl:for-each>
secondonelevelcode[<xsl:value-of select="position()-1"/>]='<xsl:value-of select="@id"/>';
thirdlevelcode[<xsl:value-of select="position()-1"/>]=thisthirdlevelcode;
thirdlevelname[<xsl:value-of select="position()-1"/>]=thisthirdlevelname;
</xsl:for-each>
<![CDATA[
eval('document.'+formname+'.'+preP+'.options[a].selected=true;');
b=0;
if (selectC!='0' )
{
b=1;
for (i=0;i<secondonelevelcode.length;i++)
{
if (selectP==secondonelevelcode[i])
{
b=i+1;
break;
}
}
cityid=b;
b=0;
for (i=0;i<thirdlevelname[cityid-1].length;i++)
{
if (selectC==thirdlevelcode[cityid-1][i])
{b=i+1;tempoption=new Option(thirdlevelname[cityid-1][i],thirdlevelcode[cityid-1][i],false,true);}
else
tempoption=new Option(thirdlevelname[cityid-1][i],thirdlevelcode[cityid-1][i]);
eval('document.'+formname+'.'+preC+'.options[i+1]=tempoption;');
}
eval('document.'+formname+'.'+preC+'.options[b].selected=true;');
}
}
function selectsecond(preP,preC,formname)
{
cityid=eval('document.'+formname+'.'+preP+'.selectedIndex;');
j=eval('document.'+formname+'.'+preC+'.length;');
for (i=1;i<j;i++)
{eval('document.'+formname+'.'+preC+'.options[j-i]=null;')}
if (cityid!="0")
{
citytrueid=eval('document.'+formname+'.'+preP+'.selectedIndex;');
citytrueid=eval('document.'+formname+'.'+preP+'.options['+citytrueid+'].value;');
for (i=0;i<secondonelevelcode.length;i++)
{
if (citytrueid==secondonelevelcode[i])
{
citytrueid=i+1;
break;
}
}
for (i=0;i<thirdlevelname[citytrueid-1].length;i++)
{
tempoption=new Option(thirdlevelname[citytrueid-1][i],thirdlevelcode[citytrueid-1][i]);
eval('document.'+formname+'.'+preC+'.options[i+1]=tempoption;');
}
}
}
]]>
</script>
<!-- 企业性质javascript 结束--> 大家可以看到这个很麻烦,本来想用dwr,最后用了这个,头疼,不建议采用,可以学习学习。
发表评论
提醒: 该博客已发表在公共论坛,博客所有留言会成为论坛回贴,留言请注意遵守论坛发贴规则
- 浏览: 1336 次
- 性别:

- 来自: 西安

- 详细资料
搜索本博客
最近加入圈子
最新评论
-
javascript实现导出excel ...
谢谢您的指教
-- by wangchao_17915566 -
javascript实现导出excel ...
但这个是基于降低安全性的操作的!! 所以如果是基于内网应用的话还是不错的!!! ...
-- by 咖啡刀 -
DWR2.0中checkbox的value ...
问题描述不清楚,代码又冗长。所以没有人看是很正常的。
-- by hax -
DWR2.0中checkbox的value ...
没有人愿意看javascript代码,兄弟.... 除非他也遇到同样的错误... ...
-- by guo_david_wei -
dwr路径让我苦闷
那你能不能把你的代码贴给我看看呢?
-- by wangchao_17915566






评论排行榜