[JavaScript] cookie application-remember the user name

Source: Internet
Author: User

The previous article aboutCookieOfArticle, Encapsulates cookie. js. Next we will use an instance to apply this Js.

The most common one is to remember the user name. After a user logs on once, the user's account and password are recorded through cookies, so that the next time the user opens the page, no need to enter the account password again. AttachedCode:

 <!  Doctype html  >  <  Html  Lang  = "En-us"  >  <  Head  >      < Meta  Charset  = "UTF-8"  >      <  Title  > Cookie application-remember the user name </  Title  >  </  Head  >  <  Body  >      < Form  Action  = "#"  ID  = "Myform"  >          <  Label  For  = "Username"  > User name: </  Label  > <  Input  Type  = "Text" Name  = "Username"  ID  = "Username"   />          <  Label  For  = "Userpass"  > Password: </  Label  > <  Input  Type  = "Password"  Name = "Userpass"  ID  = "Userpass"   />          <  Input  Type  = "Submit"  Value  = "Login"   />          <  A  Href  = "Javascript :;"  > Clear records </ A  >      </  Form  >  </  Body  >  </  Html  >  <  Script  Type  = "Text/JavaScript"  SRC  = "Cookie. js" > </  Script  >  <  Script  Type  = "Text/JavaScript"  >  Window. onload  =   Function  (){  VaR  Oform =  Document. getelementbyid (  '  Myform  '  );  VaR  Otxt1  =  Document. getelementbyid (  ' Username  '  );  VaR  Otxt2  =  Document. getelementbyid (  '  Userpass  '  ); VaR  Oclear  =  Document. getelementsbytagname (  '  A  '  )[  0  ]; Otxt1.value  = Getcookie (  '  Username  '  ); Otxt2.value  =  Getcookie (  '  Userpass  '  ); Oform. onsubmit =   Function  () {Setcookie (  '  Username  '  , Otxt1.value,  30  ); Setcookie (  '  Userpass '  , Otxt2.value,  30  );} Oclear. onclick  =   Function  () {Removecookie (  '  Username  '  ); Removecookie ( '  Userpass  '  ); Otxt1.value  =   ''  ; Otxt2.value  =   ''  ;}}  </  Script > 

PS: I am bored. I learned JavaScript knowledge to write some effects at will.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.