JQuery practice (a) From the ITCAST saw a jQuery practice video (http://www.itcast.net/portal/courses/unit/198), currently do not use money, huh, I saw it last night, I think it is very good, then recorded, for future review !!!
The JQuery practice course is a series of courses. It introduces how to use JQuery to quickly develop AJAX front-end applications by means of hands-on practices of each course and examples. It also introduces HTML in front-end development, knowledge about CSS and Javascript and solutions to cross-browser differences.
In the first lesson, I not only talked about the installation and reference of some environments, but also talked about a simple user verification using jQuery's AJAX function. The video uses JAVA, so I changed him.. NET version.
Because this is a series of courses, I set up a jQueryTest project in VS to specialize in these instances. For classification, I set up css, js, handler, the images folder is used to store different files. Here, all my servers use general handlers and are stored in the handler folder. After the source code is complete, I will upload them.
The changes are also added to the instance, and jQuery is also used to implement the switchover. The Code is as follows:
The first is the code of the HTML page file. It is very simple. There are two text boxes and one button. Here I use ID to name all the buttons:
Source code
Copy (IE valid)
Print
About
- <% @ Page Language = "C #" AutoEventWireup = "true" CodeFile = "userlogin. aspx. cs" Inherits = "userlogin" %>
- <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <HtmlXmlns = "http://www.w3.org/1999/xhtml">
- <HeadRunat = "server">
- <Title>AJAX User Login</Title>
- <MetaHttp-equiv = "Content-Type" content = "text/html; charset = UTF-8">
- <LinkHref = "css/userlogin.css" rel = "stylesheet" type = "text/css"/>
- <ScriptSrc = "js/jquery. min. js" type = "text/javascript"> </Script>
- <ScriptSrc = "js/userlogin. js" type = "text/javascript"> </Script>
- </Head>
- <Body>
- <FormId = "form1" runat = "server">
- Enter the User Name:<InputType = "text" id = "userName" class = "notValue"/> <Br />
- Enter the password:<InputType = "password" id = "userPassword" class = "notValue"/> <Br />
- <InputType = "button" value = "login" id = "btnLogin"/>
- <DivId = "mes"> </Div>
- </Form>
- </Body>
- </Html>
<% @ Page Language = "C #" AutoEventWireup = "true" CodeFile = "userlogin. aspx. cs" Inherits = "userlogin" %> <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
There is no value in the opening box. The notvalueformat is supported. The source code of the Sample Table file userlogin.css is as follows:Source codeCopy (IE valid)PrintAbout
- . HasValue {/* style when the text box has a value */
- Border: 1px solid # 9EC9FF;
- }
- . NotValue {/* style when there is no value in the text box */
- Border: 1px solid # f00;
- Background: url (../images/userVerify.gif) repeat-x bottom;
- }
. HasValue {/* style when the text box has a value */border: 1px solid # 9EC9FF ;}. notValue {/* style when there is no value in the text box */border: 1px solid # f00; background: url (.. /images/userVerify.gif) repeat-x bottom ;}
The next step is to compile the JS file. The following is the source code of userlogin. js:Source codeCopy (IE valid)PrintAbout
- $ (Document). ready (function () {// after loading the page, execute this function, which is equivalent to adding onload = ....
- // Register the logon button and click the event
- $ ("# BtnLogin"). click (function (){
- // Obtain text box content and perform second transcoding to prevent Chinese garbled characters
- Var userName = encodeURI ($ ("# userName"). val ()));
- Var userPassword = encodeURI ($ ("# userPassword"). val ()));
- // Determine whether the text box contains content
- If (userName = ""){
- Alert ("Enter the user name! ");
- Return;
- }
- If (userPassword = ""){
- Alert ("enter the password! ");
- Return;
- }
- // Send data through AJAX
- $. Get ("handler/userlogin. ashx? Username = "+ userName +" & userpassword = "+ userPassword, null, function (data ){
- $ ("# Mes"). text (data );
- });
- });
- // Register the keyboard button event in the text box
- $ ("# UserName"). keyup (function (){
- // Alert ($ ("# userName"). val ());
- If ($ ("# userName"). val ()! = ""){
- // If the content in the text box is not empty, switch the style to hasValue.
- $ ("# UserName"). removeClass ("notValue"). addClass ("hasValue ");
- } Else {
- $ ("# UserName"). removeClass ("hasValue"). addClass ("notValue ");
- }
- });
- $ ("# UserPassword"). keyup (function (){
- If ($ ("# userPassword"). val ()! = "" & $ ("# UserPassword"). val ()! = Null ){
- // If the content in the text box is not empty, switch the style to hasValue.
- $ ("# UserPassword"). removeClass ("notValue"). addClass ("hasValue ");
- } Else {
- $ ("# UserPassword"). removeClass ("hasValue"). addClass ("notValue ");
- }
- });
- });
$ (Document ). ready (function () {// After the page is loaded, execute this function, which is equivalent to adding onload = .... // click the event $ ("# btnLogin") When registering the logon button "). click (function () {// obtain the content of the text box and transcode it twice to prevent Chinese garbled var userName = encodeURI ($ ("# userName "). val (); var userPassword = encodeURI ($ ("# userPassword "). val (); // determines whether the text box contains content if (userName = "") {alert ("Enter the user name! "); Return;} if (userPassword =" ") {alert (" enter the password! "); Return;} // AJAX sends data $. get (" handler/userlogin. ashx? Username = "+ userName +" & userpassword = "+ userPassword, null, function (data) {$ (" # mes "). text (data) ;}); // register the keyboard button event of the text box $ ("# userName "). keyup (function () {// alert ($ ("# userName "). val (); if ($ ("# userName "). val ()! = "") {// If the content in the text box is not empty, switch the style to hasValue $ ("# userName "). removeClass ("notValue "). addClass ("hasValue");} else {$ ("# userName "). removeClass ("hasValue "). addClass ("notValue") ;}}); $ ("# userPassword "). keyup (function () {if ($ ("# userPassword "). val ()! = "" & $ ("# UserPassword"). val ()! = Null) {// If the content in the text box is not empty, switch the style to hasValue $ ("# userPassword "). removeClass ("notValue "). addClass ("hasValue");} else {$ ("# userPassword "). removeClass ("hasValue "). addClass ("notValue ");}});});
There is nothing to say about the above JS code. You only need to take some time to check the jQuery API documentation. I will put the parameters required for jQuery in the attachment, including the jQuery Chinese API, jQuery version 1.2.6, CSS Reference Manual, and DHTML reference manual. Note that when you open the downloaded CHM file, in my SP3 SP3 window, a "open file-Security Warning" dialog box is displayed. I Want To deselect the "always ask before opening this file" in the dialog box, otherwise, you will not be able to see any content after opening it!
The above is a small example of the first lesson. I will go back from work tonight to continue reading the second lesson. Hey, hey !!!
- When the source code is _ use vsto open the website, it can be _.rar (21.7 KB)
- Jqueryreference data .rar (6 MB)