网络编程 发布日期:2025/11/15 浏览次数:1
本文实例讲述了jQuery使用$.ajax进行即时验证的方法。分享给大家供大家参考,具体如下:
使用jQuery和一般处理程序即时验证用户录入的学号是否重复,当光标离开输入框即给出提示。
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AddStudent.aspx.cs" Inherits="AddStudent" %>
<!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></title>
<style type="text/css">
.clsShow
{
font-size: 13px;
border: solid 1px #cc3300;
padding: 2px;
display: none;
margin-bottom: 5px;
background-color: #ffe0a3;
}
</style>
<script type="text/javascript" src="/UploadFiles/2021-04-02/jquery-1.4.2.js">
一般处理程序Check.ashx代码:
<%@ WebHandler Language="C#" class="Check" %>
using System;
using System.Web;
public class Check : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
string num = context.Request["txtNum"].ToString();
bool result = false;
if(num=="12")//为了简化代码,没有访问数据库。实际项目应查询数据库。
{
result = true;
}
context.Response.Write(result);
}
public bool IsReusable {
get {
return false;
}
}
}
希望本文所述对大家jQuery程序设计有所帮助。