1.Cookie is a small text file that is placed on the client by the Web designer. Implementation: Store a list of products that users have browsed, remembering which types of news users like to browse.
With the user's permission, you can also store the user's logon information so that users do not have to type the information each time they visit the site.
First on the code:
<!DOCTYPE HTML><HTML> <Head> <MetaCharSet= "UTF-8"> <title></title> <Scriptsrc=".. /jquery-3.2.1/jquery-3.2.1.js "></Script> <Scriptsrc= "Jquery.cookie.js"></Script> <Scriptsrc= "Color_byself.js"></Script> <Scripttype= "Text/javascript"> $(function(){ $("#btn1"). Click (function(){ $("#aaa"). Color ("Red"); }); varCookie_name= 'username'; if($.cookie (Cookie_name)) {$ ("#username"). Val ($.cookie (Cookie_name)); } $("#remember"). Bind ("Click",function(){ if( This. Checked) {$.cookie (cookie_name,$ ("#usernam"). Val (), {path:'/', Expires:Ten}); }Else{$.cookie (cookie_name,NULL, {path:'/'}); } });
The first line defines aThe Cookie_name property is then judged if $.cookie (Cookie_name) is true, and when there is a record in the cookie is true,
If the user name in the cookie record is actually assigned to the text box after the decision is valid, nothing will be done if it is false.
Then write the checkbox to check the trigger event, first of all to determine whether to tick, if true to execute. Cookie method, method has three parameters, the first is the property name, here is Cookie_name
The second is the value of the property, and here is the $ ("#usernam"). Val (), the third is the address and time of storage, here is path: '/' and expires:10. PS: The time here is a unit of the day
}); </Script> </Head> <Body> <Div>User name:<inputtype= "text"name= "username"ID= "username"value= "Please enter user name" /> <inputtype= "checkbox"name= "Remember"ID= "Remember"value="" />Remember user name<BR/> <DivID= "AAA">I'm a little text for testing<inputtype= "button"name= "BTN1"ID= "BTN1"value= "discoloration" /> </Div> </Div> </Body></HTML>
There is also a section of CSS code:
;(function ($) { $.fn.extend ({ "color":function (value) { if (value = = undefined) { return this.css (" Color "); } Else { return this.css ("Color", value); } }) }) (jQuery);
Here, the first piece of code is to write the code of the HTML, while writing jquery code, implemented a click to replace the text color code, and a cookie based on the text box can remember the user name of the time code.
The code to change the color is mainly to be able to practice how to write a small plugin in a separate JS file, in order to understand the plug-in applications and links
The code of the cookie is the use of the learning cookie plugin.
08.01 "JQuery"--cookie plug-in simple application and write their own simple replacement color plugin