- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 ASP.NET 内容表单,其中包含几个文本框。我需要为这些文本框实现 JQuery 所需的字段验证。给出下面的代码,我无法弄清楚如何使用 JQuery 来完成它。即使花了一些时间谷歌搜索后,我仍然感到困惑。感谢您提前的帮助
<%@ MasterType VirtualPath="~/Shared/Module.master" %>
<%@ Page MasterPageFile="~/Shared/Module.master" Language="C#" AutoEventWireup="true"
CodeFile="CreateObjective.aspx.cs" Inherits="SG.ALD.Schema.Modules.Manage.CreateObjective"
ClientIDMode="Static" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxtoolkit" %>
<%@ Register Assembly="SG.Practices.Framework.CoreServices.Client.Web.WebUIControls"
Namespace="SG.Practices.Framework.CoreServices.Client.Web.WebUIControls" TagPrefix="cc1" %>
<%@ Register Src="../../../SharedControl/AuditDataControl.ascx" TagName="AuditDataControl"
TagPrefix="uc1" %>
<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="SubModuleContent">
<script type="text/javascript" src="C:\HOMEWARE\Aldschema\trunk\Src\Webserver\WEBUI\Scripts\jquery-1.4.1-vsdoc.js">
PageInitialization();
$('input[id$=txtObjectiveCode]').keydown(function () {
alert('jquery!!!!!!');
});
function PageInitialization() {
PageJQInitialization();
}
function EndRequestHandler(sender, args) {
if (args.get_error() == undefined) {
PageJQInitialization();
}
}
}
</script>
<table border="0" cellspacing="0" cellpadding="0" width="660px" align="center">
<tr>
<td width="5px" class="tableleft">
</td>
<td class="tablemiddle">
<asp:Image runat="server" ID="roleImage" SkinID="gridHeaderImage" /><asp:Label runat="server"
ID="moduleHeaderCaption" />
</td>
<td width="5px" class="tableright">
</td>
</tr>
<tr>
<td valign="top" class="tablelineleft" width="1px">
</td>
<td valign="top" border="0" cellspacing="0" cellpadding="0">
<table width="600px">
<tr>
<td align="center" colspan="2">
<asp:Label ID="lblmsg" runat="server" CssClass="lgt" ForeColor="#CC0000"></asp:Label>
</td>
</tr>
<tr>
<td style="width: 30%" align="right">
</td>
<td style="width: 70%" align="left">
</td>
</tr>
<tr>
<td style="width: 30%; height: 22px;" align="right" class="lgt">
<span runat="server" style="color: #ff0033">*</span>Objective Code:
</td>
<td style="width: 70%; height: 22px;" align="left" class="txtwt">
<asp:TextBox ID="txtObjectiveCode" runat="server" TabIndex="1" MaxLength="50"
SkinID="textboxMandatory" ></asp:TextBox>
<%-- <tr>
<td style="width: 30%" align="right" class="lgt">
<span style="color: #ff0033">*</span> Select City:
</td>
<td style="width: 70%" align="left" class="txtwt">
<div class="mandatoryField" style="width:150px">
<asp:DropDownList ID="drpCity" TabIndex="6" runat="server" AutoPostBack="true" Width="150px" OnSelectedIndexChanged="drpCity_SelectedIndexChanged">
</asp:DropDownList>
</div>
</td>
</tr>
<tr>
<td style="width: 30%" align="right" class="lgt">
<span style="color: #ff0033">*</span> Select Location:
</td>
<td style="width: 70%" align="left" class="txtwt">
<div class="mandatoryField" style="width:150px">
<asp:DropDownList ID="drpSite" Width="150px" TabIndex="7" runat="server">
</asp:DropDownList>
</div>
</td>
</tr>--%> <%-- <tr>
<td style="width: 30%" align="right" class="lgt">
<span style="color: #ff0033">*</span> Select City:
</td>
<td style="width: 70%" align="left" class="txtwt">
<div class="mandatoryField" style="width:150px">
<asp:DropDownList ID="drpCity" TabIndex="6" runat="server" AutoPostBack="true" Width="150px" OnSelectedIndexChanged="drpCity_SelectedIndexChanged">
</asp:DropDownList>
</div>
</td>
</tr>
<tr>
<td style="width: 30%" align="right" class="lgt">
<span style="color: #ff0033">*</span> Select Location:
</td>
<td style="width: 70%" align="left" class="txtwt">
<div class="mandatoryField" style="width:150px">
<asp:DropDownList ID="drpSite" Width="150px" TabIndex="7" runat="server">
</asp:DropDownList>
</div>
</td>
</tr>--%>
</td>
</tr>
<tr>
<td style="width: 30%" align="right" class="lgt">
<span style="color: #ff0033">*</span>Description:
</td>
<td style="width: 70%" align="left" class="txtwt">
<asp:TextBox ID="txtDescription" runat="server" Columns="30" TabIndex="2" MaxLength="25"
SkinID="textboxMandatory" Width="349px"></asp:TextBox>
</td>
</tr>
<tr>
<td style="width: 30%" align="right" class="lgt">
</td>
<td style="width: 70%" align="left" class="txtwt">
</td>
</tr>
<tr>
<td style="width: 30%" align="right" class="lgt">
</td>
<td style="width: 70%" align="left" class="txtwt">
</td>
</tr>
<%-- <tr>
<td style="width: 30%" align="right" class="lgt">
<span style="color: #ff0033">*</span> Select City:
</td>
<td style="width: 70%" align="left" class="txtwt">
<div class="mandatoryField" style="width:150px">
<asp:DropDownList ID="drpCity" TabIndex="6" runat="server" AutoPostBack="true" Width="150px" OnSelectedIndexChanged="drpCity_SelectedIndexChanged">
</asp:DropDownList>
</div>
</td>
</tr>
<tr>
<td style="width: 30%" align="right" class="lgt">
<span style="color: #ff0033">*</span> Select Location:
</td>
<td style="width: 70%" align="left" class="txtwt">
<div class="mandatoryField" style="width:150px">
<asp:DropDownList ID="drpSite" Width="150px" TabIndex="7" runat="server">
</asp:DropDownList>
</div>
</td>
</tr>--%>
<tr>
<td style="width: 30%" align="right" class="lgt">
</td>
<td style="width: 70%" align="left" class="txtwt">
</td>
</tr>
<tr>
<td style="width: 30%" align="right" class="lgt">
</td>
<td style="width: 70%" align="left" class="txtwt">
</td>
</tr>
<tr>
<td style="width: 30%" align="right">
</td>
<td style="width: 0%" align="left">
<table style="width: 100%">
<tr>
<td width="10%">
<asp:Button ID="btnSave" runat="server" TabIndex="10" Text="Save" CssClass="button_70x20"
OnClick="btnSave_Click" AccessKey="a" height="22px" width="71px" />
</td>
<td>
<asp:Button ID="btnCancel" runat="server" TabIndex="11" Text="Cancel" CausesValidation="False"
CssClass="button_70x20 cancel" OnClick="btnCancel_Click" AccessKey="c"
Width="71px" />
<asp:Button ID="btnAudit" runat="server" Text="View Audit" TabIndex="12" CausesValidation="False"
CssClass="button_90x20" OnClick="btnAudit_Click" AccessKey="w"
Visible="False" Width="136px" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
<td valign="top" class="tablelineright">
</td>
</tr>
<tr>
<td class="tablefooterleft">
</td>
<td class="tablefootermiddle">
</td>
<td class="tablefooterright">
</td>
</tr>
</table>
<uc1:AuditDataControl ID="AuditDataControl1" runat="server" />
</asp:Content>
最佳答案
1. Load the Jquery framework and the JQuery tooltip plugin. Also load the stylesheet for use by the tooltip. Note: Code below shows we're loading a javascript file.
<script src="Scripts/addrecord-script.js" type="text/javascript"></script>
Inside the javascript file 3 scripts are being loaded:
loadJavaScriptFile("Scripts/jquery-1.4.1.min.js");
loadJavaScriptFile("Scripts/jquery.validate.min.js");
loadJavaScriptFile("Scripts/jquery.metadata.min.js");
function loadJavaScriptFile(jspath) {
document.write('<script type="text/javascript" src="' + jspath + '"><\/script>');
}
2. Initialize the JQuery UI Tooltip plugin.
$(function () {
InitializeValidation();
});
function InitializeValidation() {
var validator = $("#MasterPageForm1").bind("invalid-form.validate", function () { }).validate({
errorElement: "em",
errorPlacement: function (error, element) {
error.appendTo(element.parent("td").next("td"));
},
success: function (label) {
label.text("ok!").addClass("success");
}
});
}
There are a few things to notice here. We're telling the plugin to validate everything inside the "#MasterPageForm1" form. "#MasterPageForm1" is the form ID which is located in the master page. See code below.
<form id="MasterPageForm1" class="cmxform" runat="server">
Another thing to notice in the initalization is that the errors will be placed in the next td tag from the object being validated.
errorPlacement: function (error, element) {
error.appendTo(element.parent("td").next("td"));
And lastly, when the requirement for validation is satisfied a text "ok" is shown as well as a class call "success" is added. The added class just shows a check mark before the "ok" text.
success: function (label) {
label.text("ok!").addClass("success");
}
3. Add an inline error validation in the CssClass property of the ASP.NET web control.
<tr>
<td>Person ID:</td>
<td> <span style="color: red;">*</span> </td>
<td><asp:TextBox ID="TxtPersonID" MaxLength="50" CssClass="{required:true, messages:{required:'Person ID is required!'}}" runat="server" /></td>
<td></td>
</tr>
关于jquery - 如何在 ASP.NET 内容表单中使用 JQuery 验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9663408/
在 JSF2 应用程序中遇到验证属性的问题时,有两种主要方法。 使用 Annotation 在 ManagedBean 上定义验证 @ManagedBean public class MyBean {
我想实现一个不常见的功能,我认为 jquery 验证插件将是最好的方法(如果您在没有插件的情况下建议和回答,我们也会欢迎)。我想在用户在输入字段中输入正确的单词后立即隐藏表单。我试过这个: $("
我有几个下拉菜单(类名为month_dropdown),并且下拉菜单的数量不是恒定的。我怎样才能为它们实现 NotEqual 验证。我正在使用 jQuery 验证插件。 这就是我写的 - jQuery
我设法制作了这个网址验证代码并且它起作用了。但我面临着一个问题。我认为 stackoverflow 是获得解决方案的最佳场所。 function url_followers(){ var url=do
我目前正在使用后端服务,该服务允许用户在客户端应用程序上使用 Google Games 库登录。 用户可以通过他们的 gplay ID 向我们发送信息,以便登录或恢复旧帐户。用户向我们发送以下内容,包
我正在尝试验证输入以查看它是否是有效的 IP 地址(可能是部分地址)。 可接受的输入:172、172.112、172.112.113、172.112.113.114 Not Acceptable 输入
我从 Mongoose 验证中得到这条消息: 'Validator failed for path phone with value ``' 这不应该发生,因为不需要电话。 这是我的模型架构: var
我一直在尝试使用Python-LDAP (版本 2.4.19)在 MacOS X 10.9.5 和 Python 2.7.9 下 我想在调用 .start_tls_s() 后验证与给定 LDAP 服务
我正在处理一个仅与 IE6 兼容的旧 javascript 项目(抱歉...),我想仅在 VS 2017 中禁用此项目的 ESLint/CSLint/Javascript 验证/CSS 验证。 我知道
我正在寻找一种方法来验证 Spring 命令 bean 中的 java.lang.Double 字段的最大值和最小值(一个值必须位于给定的值范围之间),例如, public final class W
我正在尝试在 springfuse(JavaEE 6 + Spring Framework (针对 Jetty、Tomcat、JBoss 等)) 和 maven 的帮助下构建我的 webapps 工作
我试图在我们的项目中使用 scalaz 验证,但遇到了以下情况: def rate(username: String, params: Map[String, String]): Validation
我有一个像这样的 Yaml 文件 name: hhh_aaa_bbb arguments: - !argument name: inputsss des
我有一个表单,人们可以单击并向表单添加字段,并且我需要让它在单击时验证这些字段中的值。 假设我单击它两次并获取 2 个独立的字段集,我需要旋转 % 以确保它在保存时等于 100。 我已放入此函数以使其
在我的页面中有一个选项可以创建新的日期字段输入框。用户可以根据需要创建尽可能多的“截止日期”和“起始日期”框。就像, 日期_to1 || date_from1 日期到2 ||日期_from2 date
我有一个像这样的 Yaml 文件 name: hhh_aaa_bbb arguments: - !argument name: inputsss des
有没有办法在动态字段上使用 jquery 验证表单。 我想将其设置为必填字段 我正在使用 Jsp 动态创建表单字段。 喜欢 等等...... 我想使用必需的表单字段验证此表单字段。 最佳答
嗨,任何人都可以通过提供 JavaScript 代码来帮助我验证用户名文本框不应包含数字,它只能包含一个字符。 最佳答案 使用正则表达式: (\d)+ 如果找到匹配项,则字符串中就有一个数字。 关于J
我有两个输入字段holidayDate和Description(id=tags) $(document).ready(function() {
我遇到了这个问题,这些验证从电子邮件验证部分开始就停止工作。 我只是不明白为什么即使经过几天的观察,只是想知道是否有人可以在这里指出我的错误? Javascript部分: function valid
我是一名优秀的程序员,十分优秀!