我在.aspx页面中有一个多选下拉列表。
<asp:DropDownList ID="ddlProduct" runat="server" CssClass="form-control ui fluid dropdown" multiple="">
</asp:DropDownList>
我的要求是我从下拉列表中选择的任何产品(它是从DB填充的),它应该显示产品的文本框,您应在其中输入总数量。这是文本框的代码
<label class="control-label">Total Quantity Purchased</label>
<div class="col-md-12 hideshow1" >
<asp:TextBox ID="Product1Textbox" runat="server" CssClass="form-control" MaxLength="3"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="1Purchase quantity is required" CssClass="text-danger" ControlToValidate="Product1Textbox"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="Purchase quantity is invalid" ControlToValidate="Product1Textbox"
ValidationExpression="\d+"></asp:RegularExpressionValidator>
</div>
<div class="col-md-12 hideshow3">
<asp:TextBox ID="Product2Textbox" runat="server" CssClass="form-control" MaxLength="3"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="2Purchase quantity is required" CssClass="text-danger" ControlToValidate="Product2Textbox"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server" ErrorMessage="Purchase quantity is invalid" ControlToValidate="Product2Textbox"
ValidationExpression="\d+"></asp:RegularExpressionValidator>
</div>
<div class="col-md-12 hideshow4">
<asp:TextBox ID="Product3Textbox" runat="server" CssClass="form-control" MaxLength="3"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ErrorMessage="3Purchase quantity is required" CssClass="text-danger" ControlToValidate="Product3Textbox"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator4" runat="server" ErrorMessage="Purchase quantity is invalid" ControlToValidate="Product3Textbox"
ValidationExpression="\d+"></asp:RegularExpressionValidator>
</div>
我正在使用Jquery来显示/隐藏文本框。我想要的是只应为所选产品启用RequiredFieldValidator。
<script>
$('.ui.fluid.dropdown').dropdown();
$('.ui.fluid.dropdown').change(function () {
$(".hideshow1").hide();
ValidatorEnabled($("<%=RequiredFieldValidator1%>"), false);
$(".hideshow3").hide();
ValidatorEnabled($("<%=RequiredFieldValidator3%>"), false);
$(".hideshow4").hide();
ValidatorEnabled($("<%=RequiredFieldValidator4%>"), false);
$(".ui.fluid.dropdown option:selected").each(function () {
var selection = "";
selection = ".hideshow" + $(this).val();
$(selection).show();
ValidatorEnabled($("<%=RequiredFieldValidator1%>"), true);
});
});
</script>
我在控制台
中收到此错误“未捕获的TypeError:无法设置未定义(...)”的属性'可见性'。
默认情况下,所有文本框Div都是“display:none”。
答案 0 :(得分:1)
在&lt;%=前面使用“#”
ValidatorEnabled($("#<%=RequiredFieldValidator1%>"), false);
答案 1 :(得分:0)
我建议使用v7_exit_coherency_flush()
。仅当父CustomValidators
显示为<div>
且文本框为空时,才会触发以下验证程序。
block