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.