zoukankan      html  css  js  c++  java
  • 我的第一个JqueryDemo

    实例功能说明:

       当点击"获取时间"的按钮时,能够在不刷新页面的前提下获取系统当前时间. 

    1:前台页面代码:

     <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Test.aspx.cs" Inherits="WebApplication1.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">
    <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <head runat="server">
        <title></title>
        <script type="text/javascript" language="javascript">

            $(
    function () {
                $(
    "#btnGet").click(function () {
                    $.post(
    "DataGet.ashx", { "ID"1"Name""黎明" },
                                        
    function (data, state) {
                                            
    if (state == "success") {
                                                $(
    "#txtDate").val(data);
                                            }
                                        }
                                    );
                });
            });
        
    </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <input type="text" id="txtDate" /><input type="button" id="btnGet"  value="获取时间"/>
        </div>
        </form>
    </body>

    </html> 

     2:一般处理程序:DataGet.ashx,代码如下:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;

    namespace WebApplication1
    {
        /// <summary>
        
    /// DataGet 的摘要说明
        
    /// </summary>
        public class DataGet : IHttpHandler
        {

            public void ProcessRequest(HttpContext context)
            {
                context.Response.ContentType = "text/plain";
               // context.Response.Write("Hello World");
                context.Response.Write(DateTime.Now.ToLongTimeString());
            }

            public bool IsReusable
            {
                get
                {
                    return false;
                }
            }
        }

    } 

     在实践中最容易出现错误的地方是:由于括号太多,而且都是使匿名方法,所以容易少了括号或多打括号.

  • 相关阅读:
    win7下virtualbox遇到的问题
    2.5年, 从0到阿里
    TCP/IP入门(4) --应用层
    TCP/IP入门(3) --传输层
    TCP/IP入门(2) --网络层
    TCP/IP入门(1) --链路层
    Socket编程实践(13) --UNIX域协议
    Socket编程实践(12) --UDP编程基础
    Socket编程实践(10) --select的限制与poll的使用
    Socket编程实践(9) --套接字IO超时设置方法
  • 原文地址:https://www.cnblogs.com/zhangzt/p/2197819.html
Copyright © 2011-2022 走看看