我使用以下 jquery 来验证特定的 div。
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#btnNext').click(function () {
if ($('#page1 input[id$=txt_companyname]').val() == "") {
alert('company Name is Blank!');
$('#page1 input[id$=txt_companyname]').focus();
}
else if ($('#page1 input[id$=txt_headoff]').val() == "") {
alert('Password is Blank!');
$('#page1 input[id$=txt_headoff]').focus();
}
});
});
</script>
我在此页面中有按钮,如果我单击 btn 而不填写这些字段,则应显示警报消息。
<div id="page1" runat="server" style=" padding-left:10px">
<div class="divsize">
<div class="labelsize"><asp:Label ID="lbl_companyname" runat="server" Text="1. Name of the Company" ></asp:Label></div>
<div class="labelcolon"><asp:Label ID="Label2" runat="server" Text=":" ></asp:Label></div>
<div class="labelsize"><asp:TextBox ID="txt_companyname" runat="server" Width="250px" ></asp:TextBox></div>
</div>
<div class="divsize">
<div class="labelsize"><asp:Label ID="lbl_headoff" runat="server" Text="2. a) Head Office / Registered Office" ></asp:Label></div>
<div class="labelcolon"><asp:Label ID="Label3" runat="server" Text=":"></asp:Label></div>
<div class="labelsize"><asp:TextBox ID="txt_headoff" runat="server"
TextMode="MultiLine" Width="250px" ></asp:TextBox></div>
</div>
</div>