我已经模拟了一个非常简单的页面,我非常困惑为什么当我在 2 个文本框之间切换时 javascript 不会触发:-
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" inherits="Checkout_test" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>c</title>
<script type="text/javascript">
function checkthisvalue(source, args) {
alert('hello');
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lbl1" AssociatedControlID="txtUsername" Text="1:" runat="server" />
<asp:TextBox runat="server" CssClass="username" ID="txtUsername" ValidationGroup="vg"></asp:TextBox>
<asp:CustomValidator Enabled="true" ID="cvUsername" Display="Dynamic" ValidationGroup="vg" ControlToValidate="txtUsername" EnableClientScript="true" ClientValidationFunction="checkthisvalue" ValidateEmptyText="true" runat="server">*</asp:CustomValidator>
<asp:Label ID="lbl2" AssociatedControlID="txtPassword" Text="2:" runat="server" />
<asp:TextBox runat="server" CssClass="username" ID="txtPassword"></asp:TextBox>
<asp:CustomValidator Enabled="true" ID="cvPassword" Display="Dynamic" ControlToValidate="txtPassword" EnableClientScript="true" ClientValidationFunction="checkthisvalue" ValidateEmptyText="true" runat="server"></asp:CustomValidator>
</div>
</form>
</body>
</html>
请注意,两个 CustomValidators 都有 ValidateEmptyText=true
我已经在 IE 和 Chrome 中尝试过了,但没有成功。