JS二级联动选择框动态创建和编辑实现
来源:互联网 发布:淘宝刹那数码2店怎么样 编辑:程序博客网 时间:2024/05/17 07:11
网上关于二级联动选择框的实现很多,但是编辑页面的展示却不多。尤其是动态加载一级分类的,会比较复杂。此次业务选择了动态加载一级分类,下次再来写静态加载一级分类。
<script type="text/javascript">//声明一级分类数组 var topClassNames=['请选择','产品与服务','解决方案','成功案例','生态伙伴']; //声明二级分类数组 var secondClassNames=[ [''], ['跨企业的云平台应用','智能工厂','智能车间/产线','智能单元'], ['通用解决方案','行业解决方案'], ['无'], ['无'] ]; function createTopClassNames(){ for(var i in topClassNames){ if('${B2bIntellmakeCapabilityInfo.topClassName}'==topClassNames[i]) { var p=1;//设置标志,当有一级分类参数传来时,此时处于编辑界面,被selected展示 $("#topClassName").append("<option value="+topClassNames[i]+" selected='selected'>"+topClassNames[i]+"</option>"); } //此时处于添加页面 else $("#topClassName").append("<option value="+topClassNames[i]+">"+topClassNames[i]+"</option>"); } } function createSecondClassNames(){ $("#secondClassName").empty(); //获取一级分类选中项的索引 var index=topClassName.selectedIndex; //将secondClassName下的所有原有option移除 secondClassName.options.length=0; //添加对应二级分类下拉列表 for(var i in secondClassNames[index]){ $("#secondClassName").append("<option value="+secondClassNames[index][i]+">"+secondClassNames[index][i]+"</option>"); } if($('#topClassName option:selected').val()=='生态伙伴')//当一级分类是生态伙伴的时候,图片上传提示改为上传成员图片 { document.getElementById("team").style.display=""; document.getElementById("capability").style.display="none"; } else{ document.getElementById("team").style.display="none"; document.getElementById("capability").style.display=""; }} window.onload = function(){ //联动选择框 //声明获取的一级分类节点元素 var topClassName=document.getElementById("topClassName"); //声明获取的二级分类节点元素 var secondClassName=document.getElementById("secondClassName"); createTopClassNames(); if(p=1){//如果传来一级分类时,二级分类不联动 //获取一级分类选中项的索引 var index=topClassName.selectedIndex; alert("index",index); //将secondClassName下的所有原有option移除 secondClassName.options.length=0; //添加对应二级分类下拉列表 for(var i in secondClassNames[index]){ if('${B2bIntellmakeCapabilityInfo.secondClassName}'==secondClassNames[index][i]) { $("#secondClassName").append("<option value="+secondClassNames[index][i]+" selected='selected'>"+secondClassNames[index][i]+"</option>"); } else{ $("#secondClassName").append("<option value="+secondClassNames[index][i]+">"+secondClassNames[index][i]+"</option>"); } }/* $("#secondClassName").append("<option value='${B2bIntellmakeCapabilityInfo.secondClassName}'selected='selected'>"+'${B2bIntellmakeCapabilityInfo.secondClassName}'+"</option>"); */ p=0; } topClassName.onchange=createSecondClassNames; //点击一级分类进行加载二级分类 }</script> <body> <tr> <th width="20%"><font color="red">* </font>分区: </th> <td> <select id="topClassName" name="topClassName" value="$('#topClassName option:selected').val()"></select> <select id="secondClassName" name="secondClassName" value="$('#secondClassName option:selected').val()"></select> </td> </tr></body>---------
阅读全文
0 0
- JS二级联动选择框动态创建和编辑实现
- js实现省市选择二级联动
- JQuery实现二级 select框联动选择
- js 实现二级联动
- js实现二级联动
- JS实现二级联动
- js实现二级联动
- 二级联动选择框
- js的二级联动实现省份城市的选择
- [js]实现简单的省市二级联动下拉选择菜单
- asp.net js实现dropdownlist二级联动(动态)
- asp.net js实现dropdownlist二级联动(动态)
- JQury实现二级联动和<select>分类选择移动
- jsp+js二级、三级联动选择框(05年版)
- js实现省市二级联动
- js二级联动的实现
- js 实现 二级联动菜单
- js实现二级下拉联动
- JAXB validation failed because the necessary plug-ins were unavailable
- Java中Map接口的遍历
- Spring的事务管理器用法
- 初始化sentry报错/CDH中添加sentry服务失败----解决方法
- spring boot入门学习
- JS二级联动选择框动态创建和编辑实现
- unity 判断物品是否出现在角色面前
- 安卓双向滑动的实现方法
- Sublime Text3 配置TypeScript,使其高亮,提示
- 数据库表查询的内连接、外连接、交叉连接实现方式
- read: unexpected EOF
- 行为型模式总结篇(1)
- iOS之《Effective Objective-C 2.0》读书笔记(50)
- JOSN语法以及和XML的比较