我有一张桌子,它有 2 列。第一列是主下拉选项列表,第二列是主下拉选项的相应子下拉列表。
单行一切正常,但是一旦我有多行,就不会从子下拉菜单中选择任何内容。
下面是重现此问题的简单 html 和 JavaScript。如果您取消注释第二行,您将看到问题。希望有人可以帮助我。
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<script language="JavaScript">
function SubCat(cn, scn, scnm)
{
this.CatNum = cn;
this.SubcatNum = scn;
this.SubcatName = scnm;
}
var subcatInfo = new Array(
new SubCat('26', '1', 'MainOpt1_SubOpt1'),
new SubCat('26', '2', 'MainOpt1_SubOpt2'),
new SubCat('27', '3', 'MainOpt2_SubOpt1'),
new SubCat('27', '4', 'MainOpt2_SubOpt2')
);
function doCategory(sel) {
var ix;
var subcat = sel.form.repairSubcategoryCode;
// regardless of what else we do, we wipe out all the
// options in the subcategory dropdown by
// going backwards, removing selected options
for (ix = subcat.options.length - 1; ix >= 0; --ix) {
subcat.options[ix] = null;
}
// now, did the user select a category?
if (sel.selectedIndex == 0) {
// no...so give user the "no subcats" msg
subcat.options[0] = new Option("-- no subcategories yet --", "0");
return; // and we are done
}
// yes, so get the appropriate subcategories:
subcat.options[0] = new Option("-- choose a subcategory below --", "0");
// what category number was selected?
var catnum = sel.options[sel.selectedIndex].value;
var cursc = 0;
for (ix = 0; ix < subcatInfo.length; ++ix) {
// looking for all subcat's with the requested category number
var subcatObj = subcatInfo[ix];
if (subcatObj.CatNum == catnum) {
subcat.options[++cursc] = new Option(subcatObj.SubcatName,
subcatObj.SubcatNum);
}
}
}
</script language="JavaScript">
<form name="priceOpinionForm" method="post" action="/brokerPriceOpinion.do">
<table id="repirImprTab">
<tr>
<td>
<select name="repairTypeCode" onchange="doCategory(this)">
<option value="-1">Select Repair Type</option>
<option value="26">MainOpt1</option>
<option value="27">MainOpt2</option>
</select>
</td>
<td>
<select name="repairSubcategoryCode" >
<OPTION Value="-1">-- now subcategories yet --</option>
</select>
</td>
</tr>
<!--
<tr>
<td>
<select name="repairTypeCode" onchange="doCategory(this)">
<option value="-1">Select Repair Type</option>
<option value="25">Septic Maintenance</option>
<option value="26">Bathroom Items</option>
<option value="27">Cabinets & Shelves</option>
<option value="28">Counter Tops</option>
</select>
</td>
<td>
<select name="repairSubcategoryCode">
<OPTION Value="-1">-- now subcategories yet --</option>
</select>
</td>
</tr>
-->
</table>
</form>
</body>
</html>