JS实现下拉框的动态添加(附效果)_javascript技巧
程序员文章站
2024-02-01 15:30:54
...
效果展示:
动态添加下拉框
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实现防止sql注入的通用方法
下一篇: SQL Server数据库操作
推荐阅读
-
JS实现下拉框的动态添加(附效果)_javascript技巧
-
js实现动态添加、删除行、onkeyup表格求和示例_javascript技巧
-
js实现的定时关闭页面或定时提醒效果代码_javascript技巧
-
JS+CSS实现淡入式焦点图片幻灯切换效果的方法_javascript技巧
-
JS实现点击图片在当前页面放大并可关闭的漂亮效果_javascript技巧
-
js实现iframe动态调整高度的代码_javascript技巧
-
原生js实现查找/添加/删除/指定元素的class_javascript技巧
-
JS仿淘宝实现的简单滑动门效果代码_javascript技巧
-
JS图片自动轮换效果实现思路附截图_javascript技巧
-
用js实现计算代码行数的简单方法附代码_javascript技巧