[研究] NuGet 對 jQuery.Validation 1.19.2 安裝測試
2020-08-27
2022-03-30更新
環境:Visual Studio 2022 + ASP.NET + WebForm + Web Application + C#
主要是安裝
jquery.validate-vsdoc.js
jquery.validate.js
jquery.validate.min.js
範例 Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"
Inherits="WebApplication2.Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script src="Scripts/jquery-3.6.0.js"></script>
<script src="Scripts/jquery.validate.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" required runat="server">
</asp:TextBox><br />
<asp:Button ID="Button1" runat="server" Text="Button" />
</div>
</form>
</body>
</html> |
測試,不填寫,按下 Button 後的結果。
根據3個.js檔案中的訊息,必填欄位的訊息應該是 This field is required. ,而且是黑色字體。
要變成紅色可在<head>和</head>間增加
<style>
.error {
color:red;
}
</style> |
但是實際上顯示紅色中文「這是必要欄位」,但是3個.js檔案中搜尋不到此字串。
**********
另外它好像和 ASP.NET 的 RequiredFieldValidator 控制項衝突,會導致 jQuery.Validation 無法使用。
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
ControlToValidate="TextBox2" ErrorMessage="必填"
ForeColor="Red" runat="server"></asp:RequiredFieldValidator>
|
(完)
相關
jQuery Validate | 菜鸟教程
https://www.runoob.com/jquery/jquery-plugin-validate.html




沒有留言:
張貼留言