(Forget whether both mailboxes have this function ).
How does this function work?
Timing, we know how to get it, but what about saving it? Maybe we can store data by hiding domains and other means. However, this has a disadvantage: After the page is refreshed, data will be lost.
At this time, it is our turn to focus little on, and it is estimated that many people do not know the UserData Behavior (userData Behavior) debut:
What is this UserData? How to use it ?, I will repost an article about it at the end of the article.
Now, let's look at the example: no code, no truth:
Copy codeThe Code is as follows:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Title> new document </title>
<Meta name = "generator" content = "editplus"/>
<Meta name = "author" content = ""/>
<Meta name = "keywords" content = ""/>
<Meta name = "description" content = ""/>
<Script type = "text/javascript">
Window. onload = function (){
Var txtObj = document. getElementById ('txt1 ');
Var spanObj = document. getElementById ('s1 ');
// Automatically save
TxtObj. addBehavior ("# default # userData ");
Var saveTimer = setInterval (function (){
TxtObj. setAttribute ('ovalue', txtObj. value );
TxtObj. save ('saveddata ');
SpanObj. innerText = 'data is stored in: '+ (new Date ());
SetTimeout (function (){
SpanObj. innerText = '';
},1000 );
}, 10000); // save every minute
Document. getElementById ('btn1 '). attachEvent ('onclick', function (){
ClearInterval (saveTimer); // cancel saving
TxtObj. removeAttribute ('ovalue ');
});
Document. getElementById ('btn2'). attachEvent ('onclick', function (){
TxtObj. load ('saveddata ');
Alert (txtObj. getAttribute ('ovalue '));
// TxtObj. value = txtObj. getAttribute ('ovalue ');
});
};
</Script>
</Head>
<Body>
<Span id = "s1" style = "color: red;"> </span>
<P/>
<Textarea height = "500" style = "height: 500px; width: 500px;" id = "txt1">
</Textarea>
<P/>
<Input type = "button" id = "btn1" value = "Stop saving"/>
<Input type = "button" id = "btn2" value = "get saved value"/>
</Body>
</Html>
Copy the html section and run it. In fact, this is basically the same as the regular saving in the mailbox. In this case, it's okay to polish it.
Let's take a look at this article, which uses userData to save form data on the client.