JS实现下拉框的动态添加(附效果)_javascript技巧
程序员文章站
2022-04-22 16:57:29
...
效果展示:
动态添加下拉框
JS代码如下:
// JavaScript Document
$(document).ready(function (){
var CarTypeSelect = $(".CarType").children("select");
var CarColorSelect = $(".CarColor").children("select");
var CarWheelSelect = $(".CarWheel").children("select");
//给第一个下拉框的SelectChanged时间编码
CarTypeSelect.change(function (){
//取得当前下拉框的值
var CarTypeValue = $(this).val();
//当第一个下拉框内容改变的时候,第三个下拉框要隐藏起来
CarWheelSelect.parent().hide();
if(CarTypeValue !="")
{
CarColorSelect.html("");
$("").appendTo(CarColorSelect);
switch(CarTypeValue){
case "宝马":
var CarColor=["绿色","黑色"];
for(var i = 0;i$("").appendTo(CarColorSelect);
}
break;
case "奔驰":
var CarColor = ["白色","红色"];
for(var i = 0;i$("").appendTo(CarColorSelect);
}
break;
}
CarColorSelect.parent().show();
}
else
{
CarColorSelect.parent().hide();
}
});
CarColorSelect.change(function (){
var CarColorValue = $(this).val();
CarWheelSelect.html("");
if(CarColorValue != "")
{
CarWheelSelect.html("");
$("").appendTo(CarWheelSelect);
switch(CarColorValue){
case "绿色":
var CarWheel = ["绿钢","绿碳纤维"];
for(var i = 0;i$("").appendTo(CarWheelSelect);
}
break;
case "红色":
var CarWheel = ["红钢","红碳纤维"];
for(var i = 0;i$("").appendTo(CarWheelSelect);
}
break;
case "黑色":
var CarWheel = ["黑钢","黑碳纤维"];
for(var i = 0;i$("").appendTo(CarWheelSelect);
}
break;
case "白色":
var CarWheel = ["白钢","白碳纤维"];
for(var i=0;i$("").appendTo(CarWheelSelect);
}
break;
}
CarWheelSelect.parent().show();
}
else
{
CarWheelSelect.parent().hide();
}
});
});
页面初加载时:
选择车类型后:
选择车颜色后:
JS实现下拉框的动态添加,网页代码如下:
复制代码 代码如下:
JS代码如下:
复制代码 代码如下:
// JavaScript Document
$(document).ready(function (){
var CarTypeSelect = $(".CarType").children("select");
var CarColorSelect = $(".CarColor").children("select");
var CarWheelSelect = $(".CarWheel").children("select");
//给第一个下拉框的SelectChanged时间编码
CarTypeSelect.change(function (){
//取得当前下拉框的值
var CarTypeValue = $(this).val();
//当第一个下拉框内容改变的时候,第三个下拉框要隐藏起来
CarWheelSelect.parent().hide();
if(CarTypeValue !="")
{
CarColorSelect.html("");
$("").appendTo(CarColorSelect);
switch(CarTypeValue){
case "宝马":
var CarColor=["绿色","黑色"];
for(var i = 0;i
}
break;
case "奔驰":
var CarColor = ["白色","红色"];
for(var i = 0;i
}
break;
}
CarColorSelect.parent().show();
}
else
{
CarColorSelect.parent().hide();
}
});
CarColorSelect.change(function (){
var CarColorValue = $(this).val();
CarWheelSelect.html("");
if(CarColorValue != "")
{
CarWheelSelect.html("");
$("").appendTo(CarWheelSelect);
switch(CarColorValue){
case "绿色":
var CarWheel = ["绿钢","绿碳纤维"];
for(var i = 0;i
}
break;
case "红色":
var CarWheel = ["红钢","红碳纤维"];
for(var i = 0;i
}
break;
case "黑色":
var CarWheel = ["黑钢","黑碳纤维"];
for(var i = 0;i
}
break;
case "白色":
var CarWheel = ["白钢","白碳纤维"];
for(var i=0;i
}
break;
}
CarWheelSelect.parent().show();
}
else
{
CarWheelSelect.parent().hide();
}
});
});
上一篇: 正则表达式抓取网页信息
下一篇: 对慕课网 php模糊查询技术 的学习
推荐阅读
-
JS实现简单的顶部定时关闭层效果_javascript技巧
-
JS中动态添加事件(绑定事件)的代码_javascript技巧
-
js实现动态添加、删除行、onkeyup表格求和示例_javascript技巧
-
原生Js实现按的数据源均分时间点幻灯片效果(已封装)_javascript技巧
-
用CSS+JS实现的进度条效果效果_javascript技巧
-
Javascript实现动态菜单添加的实例代码_javascript技巧
-
用CSS+JS实现的进度条效果效果_javascript技巧
-
利用js动态添加删除table行的示例代码_javascript技巧
-
用js实现计算代码行数的简单方法附代码_javascript技巧
-
JS图片自动轮换效果实现思路附截图_javascript技巧