【发布时间】:2011-02-23 23:20:50
【问题描述】:
所以我有一个下拉列表和一个文本框:
<table>
<tr>
<td>Group Name: </td>
<td><%= Html.DropDownListFor(m => m.IndicationCalculatorGroupId, DropDownData.IndicationsGroup(SessionManager.Company.EntityID, ICConstants.IndicationsCalculatorGroupType), "", new { propertyName = "IndicationCalculatorGroupId", onchange = "UpdateField(this, false);GroupNameChange();" })%></td>
</tr>
<tr id="newGroupNameRow">
<td>New Group Name: </td>
<td><%= Html.TextBoxFor(m => m.IndicationCalculatorNewGroupName, new { @class = "economicTextBox", propertyName = "IndicationCalculatorNewGroupName", onchange = "UpdateField(this);" })%></td>
</tr>
</table>
我在页面上有 JQuery,它根据下拉选择显示/隐藏文本框。
function GroupNameChange()
{
$("#IndicationCalculatorGroupId").change(function() {
if ($("#IndicationCalculatorGroupId option:selected").text() == 'Create a New Group')
{
$("#newGroupNameRow").show();
}
else{
$("#IndicationCalculatorNewGroupName").val('');
$("#newGroupNameRow").hide();
}
});
}
但似乎第一次将下拉菜单更改为“创建新组”时,文本框不会显示或执行任何操作,只有当您选择其他值然后选择“创建新组”时新组”,代码是否开始工作。
什么接线不正确?
【问题讨论】:
标签: jquery html html-helper