SO上的某个人帮助我为一个选择框编写了这个脚本,它将根据下拉列表中的选择显示隐藏的行
function showNext(opt) {
takeAway()
var optMap={
"Picked Up":"#pickedup",
"Bus to alternate":"#altad2,#altad1",
"Walk to alternate":"#altad2,#altad1",
}
$(optMap[opt]).css("display","") ;
}
function takeAway(){
$("#pickedup,#altad2,#altad1").css("display", "none");
}
我需要一些可以运行 onload 的东西,所以如果已经选择了某些东西,行会显示
这是将受脚本影响的选择
<tr class="~[evenoddrow]">
<td class="bold">In the event of early dismissal I would like my child to:</td><td id="Emergclose_Action">~([01]Emergclose_Action)</td><td class="gwCen"></td>
<td><select name="eReg|Emergclose_Action" id="eReg|Emergclose_Action" onChange="showNext(value);">
<option></option><option value="Walk home as normal">Walk home as normal</option><option value="Ride the bus as normal">Ride the bus as normal</option>
<option value="Picked Up">Be picked up immediately after dismissal</option><option value="Bus to alternate">Ride the bus to an alternate address</option><option value="Walk to alternate">Walk to an alternate address</option>
</select>
</td>
</tr>
我尝试了以下,它没有工作..
function showNext(opt) {
takeAway()
var optMap={
"Picked Up":"#pickedup",
"Bus to alternate":"#altad2,#altad1",
"Walk to alternate":"#altad2,#altad1",
}
$(optMap[opt]).css("display","") ;
}
function takeAway(){
$("#pickedup,#altad2,#altad1").css("display", "none");
}
$(function(){
$('#eReg|Emergclose_Action').trigger('onchange');
});