下拉框选中值对应切换内容的效果

本文介绍了一个使用jQuery实现的下拉菜单切换显示案例。通过选择不同的车辆型号,表格会显示对应型号的详细信息,包括车辆昵称、VIN码、车牌号等。此案例展示了如何利用JavaScript和HTML结合实现动态内容展示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<!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" />
<script type="text/javascript" src="jquery.js"></script>
<title>下拉菜单中控制显示或隐藏</title>
</head>
<body>
<form>
<table>

	<thead>

		<tr>

			<td width="9%" align="right" nowrap>车辆选择</td>

			<td colspan="5" align="left">

				<select name="vinchoose" id="vinchoose">

					<option value="凯美瑞">凯美瑞</option>

					<option value="雷凌">雷凌</option>

					<option value="保时捷">保时捷</option>

					<option value="雷诺">雷诺</option>

				</select>

			</td>

		</tr>

	</thead>

	<tbody id="d1" style="">

		<tr>

			<td width="9%" align="right" nowrap>车辆昵称</td>

			<td colspan="2">

				<input type="text" id="id" value="1" disabled>

			</td>

			<td width="9%" align="right" nowrap>VIN</td>

			<td colspan="2">

				<input type="text" id="qd" value="${model.VINNO}" disabled>

			</td>

		</tr>

		<tr>

			<td width="9%" align="right" nowrap>车牌号</td>

			<td colspan="2">

				<input type="text" id="id" value="2" disabled>

			</td>

			<td width="9%" align="right" nowrap>发动机号</td>

			<td colspan="2">

				<input type="text" id="qd" value="${model.VHCENGINE}" disabled>

			</td>

		</tr>

		<tr>

			<td width="9%" align="right" nowrap>车型</td>

			<td colspan="2">

				<input type="text" id="id" value="${model.VEHICLENAME}" disabled>

			</td>

			<td width="9%" align="right" nowrap>SFX</td>

			<td colspan="2">

				<input type="text" id="qd" value="${model.SFX}" disabled>

			</td>

		</tr>

		<tr>

			<td width="9%" align="right" nowrap>车辆里程</td>

			<td colspan="2">

				<input type="text" id="id" value="${model.mileage}" disabled>

			</td>

			<td width="9%" align="right" nowrap>车辆里程最近更新时间</td>

			<td colspan="2">

				<input type="text" id="qd" value="${model.UPDATE_YEAR}-${model.UPDATE_MONTH}" disabled>

			</td>

		</tr>

	</tbody>

	<tbody id="d2" style="display:none;">

		<tr>

			<td width="9%" align="right" nowrap>车辆昵称</td>

			<td colspan="2">

				<input type="text" id="id" value="22222" disabled>

			</td>

			<td width="9%" align="right" nowrap>VIN</td>

			<td colspan="2">

				<input type="text" id="qd" value="22222" disabled>

			</td>

		</tr>

		<tr>

			<td width="9%" align="right" nowrap>车牌号</td>

			<td colspan="2">

				<input type="text" id="id" value="${model.REGISTERNO}" disabled>

			</td>

			<td width="9%" align="right" nowrap>发动机号</td>

			<td colspan="2">

				<input type="text" id="qd" value="${model.VHCENGINE}" disabled>

			</td>

		</tr>

		<tr>

			<td width="9%" align="right" nowrap>车型</td>

			<td colspan="2">

				<input type="text" id="id" value="${model.VEHICLENAME}" disabled>

			</td>

			<td width="9%" align="right" nowrap>SFX</td>

			<td colspan="2">

				<input type="text" id="qd" value="${model.SFX}" disabled>

			</td>

		</tr>

		<tr>

			<td width="9%" align="right" nowrap>车辆里程</td>

			<td colspan="2">

				<input type="text" id="id" value="${model.mileage}" disabled>

			</td>

			<td width="9%" align="right" nowrap>车辆里程最近更新时间</td>

			<td colspan="2">

				<input type="text" id="qd" value="${model.UPDATE_YEAR}-${model.UPDATE_MONTH}" disabled>

			</td>

		</tr>

	</tbody>

	<tbody id="d3" style="display:none;">

		<tr>

			<td width="9%" align="right" nowrap>车辆昵称</td>

			<td colspan="2">

				<input type="text" id="id" value="333333" disabled>

			</td>

			<td width="9%" align="right" nowrap>VIN</td>

			<td colspan="2">

				<input type="text" id="qd" value="333333" disabled>

			</td>

		</tr>

		<tr>

			<td width="9%" align="right" nowrap>车牌号</td>

			<td colspan="2">

				<input type="text" id="id" value="${model.REGISTERNO}" disabled>

			</td>

			<td width="9%" align="right" nowrap>发动机号</td>

			<td colspan="2">

				<input type="text" id="qd" value="${model.VHCENGINE}" disabled>

			</td>

		</tr>

		<tr>

			<td width="9%" align="right" nowrap>车型</td>

			<td colspan="2">

				<input type="text" id="id" value="${model.VEHICLENAME}" disabled>

			</td>

			<td width="9%" align="right" nowrap>SFX</td>

			<td colspan="2">

				<input type="text" id="qd" value="${model.SFX}" disabled>

			</td>

		</tr>

		<tr>

			<td width="9%" align="right" nowrap>车辆里程</td>

			<td colspan="2">

				<input type="text" id="id" value="${model.mileage}" disabled>

			</td>

			<td width="9%" align="right" nowrap>车辆里程最近更新时间</td>

			<td colspan="2">

				<input type="text" id="qd" value="${model.UPDATE_YEAR}-${model.UPDATE_MONTH}" disabled>

			</td>

		</tr>

	</tbody>

	<tbody id="d4" dd style="display:none;">

		<tr>

			<td width="9%" align="right" nowrap>车辆昵称</td>

			<td colspan="2">

				<input type="text" id="id" value="444444" disabled>

			</td>

			<td width="9%" align="right" nowrap>VIN</td>

			<td colspan="2">

				<input type="text" id="qd" value="44444" disabled>

			</td>

		</tr>

		<tr>

			<td width="9%" align="right" nowrap>车牌号</td>

			<td colspan="2">

				<input type="text" id="id" value="${model.REGISTERNO}" disabled>

			</td>

			<td width="9%" align="right" nowrap>发动机号</td>

			<td colspan="2">

				<input type="text" id="qd" value="${model.VHCENGINE}" disabled>

			</td>

		</tr>

		<tr>

			<td width="9%" align="right" nowrap>车型</td>

			<td colspan="2">

				<input type="text" id="id" value="${model.VEHICLENAME}" disabled>

			</td>

			<td width="9%" align="right" nowrap>SFX</td>

			<td colspan="2">

				<input type="text" id="qd" value="${model.SFX}" disabled>

			</td>

		</tr>

		<tr>

			<td width="9%" align="right" nowrap>车辆里程</td>

			<td colspan="2">

				<input type="text" id="id" value="${model.mileage}" disabled>

			</td>

			<td width="9%" align="right" nowrap>车辆里程最近更新时间</td>

			<td colspan="2">

				<input type="text" id="qd" value="${model.UPDATE_YEAR}-${model.UPDATE_MONTH}" disabled>

			</td>

		</tr>

	</tbody>

</table>
	</form>	
<script type="text/javascript">
			
			var dd="";
var map = {"凯美瑞":"d1", "雷凌":"d2", "保时捷":"d3","雷诺":"d4"}; 
	$("#vinchoose").bind("change", function(){ 
		var divId = map[this.value]; 
		document.getElementById("d1").style.display="none";
		document.getElementById(divId).style.display="";
		if(dd!=""){
			if(dd!=divId){
				document.getElementById(dd).style.display="none";
			}
		}
		dd=divId;
	}
);
</script>
<body>		
</html>
注意:使用div做的话则不能放在<table>中,所以使用<tbody>来实现效果
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值