当我在下拉菜单上选择调整时,我可以获得值,但是当呈现正确的表单时,表单中的下拉 UI 没有正确的值。它几乎可以工作,但我觉得我没有正确执行 jquery。在视图中我有 2 个不同的表单,我使用 Jquery 根据下拉选择来选择要显示的表单。
这里是 JQUERY
$(document).ready(function() {
$("#adjustments").hide();
$(".TypeClass").change(function() {
var selected = $(".TypeClass option:selected").text();
alert(selected);
if (selected == "Received") {
$("#received").show();
$("#adjustments").hide();
}
if (selected == "Adjustment") {
$("#adjustments").show();
$("#received").hide();
}
});
$(".TypeClass2").change(function() {
var selected = $(".TypeClass2 option:selected").text();
alert(selected);
if (selected == "Received") {
$("#received").show();
$("#adjustments").hide();
}
if (selected == "Adjustment") {
$("#adjustments").show();
$("#received").hide();
}
});
});
这里的观点
<div id="received">
<fieldset>
<legend>New Inventory Transaction</legend>
<table>
<tr><td>@Html.LabelFor(model => model.ItemName)</td><td>@Html.DisplayFor(model => model.ItemName)</td></tr>
<tr><td>@Html.LabelFor(model => model.ItemNumber)</td><td>@Html.DisplayFor(model => model.ItemNumber)</td></tr>
<tr><td>@Html.LabelFor(model => model.XactTypeId)</td><td>@Html.DropDownListFor(model => model.XactTypeId, (SelectList)ViewData["InvType"], "Choose Type", new { @class = "TypeClass" })</td></tr>
<tr><td>@Html.LabelFor(model => model.XactTotalCost)</td><td>@Html.EditorFor(model => model.XactTotalCost)</td></tr>
<tr><td></td><td><p> <input type="submit" value="Create" /></p></td></tr>
</table>
</fieldset>
</div>
<div id="adjustments">
<fieldset>
<legend>New Inventory Transaction</legend>
<table>
<tr><td>@Html.LabelFor(model => model.ItemName)</td><td>@Html.DisplayFor(model => model.ItemName)</td></tr>
<tr><td>@Html.LabelFor(model => model.ItemNumber)</td><td>@Html.DisplayFor(model => model.ItemNumber)</td></tr>
<tr><td>@Html.LabelFor(model => model.WharehouseName)</td><td>@Html.EditorFor(model => model.WharehouseName)</td></tr>
<tr><td></td><td><p> <input type="submit" value="Create" /></p></td></tr>
</table>
</fieldset>
</div>