08.01 "JQuery"--cookie plug-in simple application and write their own simple replacement color plugin

Source: Internet
Author: User

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

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.