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

<!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>来实现效果
  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
实现这个功能可以通过以下步骤: 1. 在 el-table 中需要显示下拉框的列中,设置 type 属性为 'selection',并且设置 selectable 属性为 true,这样列的单元格就会显示为下拉框。 2. 在 el-table 中的数据源中,为需要显示下拉框的列添加一个 options 字段,用于存放下拉框选项的。 3. 使用 slot-scope 插槽,为需要显示下拉框的列的单元格添加一个自定义模板,模板中包含一个下拉框组件 el-select 和一个显示选中的文本框。 4. 在 el-select 的 change 事件中,将选中赋给数据源中对应的项的,并且设置一个变量来标识当前单元格是否是下拉框状态。 以下是示例代码: ```html <template> <el-table :data="tableData"> <el-table-column prop="name" label="姓名"></el-table-column> <el-table-column prop="age" label="年龄"></el-table-column> <<el-table-column prop="gender" label="性别" type="selection" selectable> <template slot-scope="{ row }"> <div v-if="!row.isDropdown"> {{ row.gender }} <i class="el-icon-arrow-down" @click="toggleDropdown(row)"></i> </div> <div v-else> <el-select v-model="row.gender" @change="changeGender(row)"> <el-option v-for="option in row.options" :key="option" :label="option" :value="option"></el-option> </el-select> </div> </template> </el-table-column> </el-table> </template> <script> export default { data() { return { tableData: [ { name: '张三', age: 20, gender: '男', options: ['男', '女'], isDropdown: false }, { name: '李四', age: 30, gender: '女', options: ['男', '女'], isDropdown: false }, { name: '王五', age: 40, gender: '男', options: ['男', '女'], isDropdown: false }, ] } }, methods: { toggleDropdown(row) { row.isDropdown = true; }, changeGender(row) { row.isDropdown = false; } } } </script> ``` 在这个示例中,我们使用了一个 isDropdown 属性来标识当前单元格是否是下拉框状态,初始为 false。当用户点击单元格中的箭头图标时,会触发 toggleDropdown 方法,将 isDropdown 属性设置为 true,这样单元格会显示下拉框组件。当用户在下拉框选中了一个后,会触发 changeGender 方法,将选中赋给数据源中对应的项的 gender 属性,并且将 isDropdown 属性设置为 false,这样单元格会显示选中
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值