效果展示:
JS实现下拉框的动态添加,网页代码如下:
复制代码 代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>动态添加下拉框</title>
<script type="text/javascript" src="/UploadFiles/2021-04-02/jquery.js"><script type="text/javascript" src="/UploadFiles/2021-04-02/SelectMenu2.js"></head>
<body>
<form action="#">
<br />
<br />
<br />
<div class="CarInfo">
<span class="CarType">车类型:
<select >
<option value="请选择" selected="selected">请选择</option>
<option value="宝马">宝马</option>
<option value="奔驰">奔驰</option>
</select>
</span>
<span class="CarColor" style="display:none">车颜色:
<select>
</select>
</span>
<span class="CarWheel" style="display:none">车轮:
<select>
</select>
</span>
</div>
</form>
</body>
</html></SPAN>
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("");
$("<option value = ''>请选择</option>").appendTo(CarColorSelect);
switch(CarTypeValue){
case "宝马":
var CarColor=["绿色","黑色"];
for(var i = 0;i<CarColor.length;i++){
$("<option value='"+CarColor[i]+"'>" + CarColor[i] + "</option>").appendTo(CarColorSelect);
}
break;
case "奔驰":
var CarColor = ["白色","红色"];
for(var i = 0;i<CarColor.length;i++){
$("<option value='"+CarColor[i]+"'>" + CarColor[i] + "</option>").appendTo(CarColorSelect);
}
break;
}
CarColorSelect.parent().show();
}
else
{
CarColorSelect.parent().hide();
}
});
CarColorSelect.change(function (){
var CarColorValue = $(this).val();
CarWheelSelect.html("");
if(CarColorValue != "")
{
CarWheelSelect.html("");
$("<option value = ''>请选择</option>").appendTo(CarWheelSelect);
switch(CarColorValue){
case "绿色":
var CarWheel = ["绿钢","绿碳纤维"];
for(var i = 0;i<CarWheel.length;i++){
$("<option value='"+CarWheel[i]+"'>" + CarWheel[i] + "</option>").appendTo(CarWheelSelect);
}
break;
case "红色":
var CarWheel = ["红钢","红碳纤维"];
for(var i = 0;i<CarWheel.length;i++){
$("<option value='"+CarWheel[i]+"'>" + CarWheel[i] + "</option>").appendTo(CarWheelSelect);
}
break;
case "黑色":
var CarWheel = ["黑钢","黑碳纤维"];
for(var i = 0;i<CarWheel.length;i++){
$("<option value='"+CarWheel[i]+"'>" + CarWheel[i] + "</option>").appendTo(CarWheelSelect);
}
break;
case "白色":
var CarWheel = ["白钢","白碳纤维"];
for(var i=0;i<CarWheel.length;i++){
$("<option vaiue='"+CarWheel[i]+"'>" + CarWheel[i] + "</option>").appendTo(CarWheelSelect);
}
break;
}
CarWheelSelect.parent().show();
}
else
{
CarWheelSelect.parent().hide();
}
});
});
JS,下拉框
更新动态
- 群星 《蓝调激情》2CD[DTS-WAV分轨][1.6G]
- 李宗盛《理性与感性 作品音乐会》2CD[低速原抓WAV+CUE][1.8G]
- 群星《华语贺年金曲》K2HD[WAV+CUE][697M]
- 群星《酒廊夜色美》2CD[DTS-WAV]
- 群星《2024好听新歌35》AI调整音效【WAV分轨】
- 神秘园《讲故事的人》2019[FLAC+CUE/整轨]
- 张智霖VS许秋怡.1991-现代爱情故事【永高创意】【WAV+CUE】
- 忧欢派对.1988-忧欢派对【飞碟】【WAV+CUE】
- 群星.2009-他的沧海遗珠精选(金碟铁盒珍藏系列)【SONY】【WAV+CUE】
- 刘德华《经典金曲》[WAV+CUE][833M]
- 邓丽君《千言万语》SACD德国限量版[低速原抓WAV+CUE][1G]
- 王闻VS曼里《不老情歌》经典粤语情歌[低速原抓WAV分轨][1G]
- 英雄联盟faker有多少联赛冠军 faker联赛冠军数量介绍
- 炉石传说酒馆战棋分数等级段位介绍 酒馆战棋分数最新等级划分一览
- 野狗子奇才三姐怎么收集 野狗子奇才三姐收集攻略