This article mainly introduces the method of transferring values between the JavaScript component focus and the page anchor. It involves the operation skills of the input box and the anchor, and has some reference value, if you need it, refer to the example in this article to describe how to transfer the value between the JavaScript component focus and the page anchor. Share it with you for your reference. The specific analysis is as follows:
These two small functions are useful in some new mobile phone pages.
How can I trigger an event when I put the cursor in the input box and trigger another event when I leave the input box? Even if the user does not input anything ......
It is easy to pass values between pages, but how does one pass values between the page's anchor points?
I. Basic Objectives
There is a page with an input box and a hyperlink. These two items are not associated,
Because the function is not big, write the two functions together
1. input box function
Once the cursor is placed on the background of the dialog box, the background turns red. Once the user clicks somewhere else, the background turns gray again.
2. hyperlink
Pass the value of text = 1 to the bottom anchor at the bottom of the page through the get method. The bottom anchor has a disabled input box that keeps polling the text parameter on the address bar.
If you do not click it at the beginning, there is no text parameter, so the input box is always displayed as null
Once you click the hyperlink, the dialog box below will change to 1 after 0.5 seconds. As it is processed in milliseconds, the user feels that it is processed in real time,
There is a back hyperlink at the top of the disabled. The parameters of the cleared page are passed. If the scroll bar is pulled down again, it is displayed as null.
Note that the url of the browser is:
Ii. Production Process
You don't need to introduce any plug-ins. You just need to open an html page to write it. Please refer to the following code:
The Code is as follows:
Onfoucs
Anchor
Back
Script
/* Change the background color of the page to # eeeeee */
Window. onload = function (){
Document. bgColor = "# eeeeee ";
Polling ();
}
/* When the dialog box gets the focus, change the background color to red, and vice versa, change it to # eeeeee */
Function getFocus (){
Document. bgColor = "# ff0000 ";
}
Function loseFocus (){
Document. bgColor = "# eeeeee ";
}
/* This is the special regular expression of the parameter when the url get value is obtained */
Function getUrlParam (name ){
Var reg = new RegExp ("(^ | &)" + name + "= ([^ &] *) (& | $ )");
Var r = window. location. search. substr (1). match (reg );
If (r! = Null) return unescape (r [2]); return null;
}
/* Keep polling and check whether the get parameter is passed */
Function synchronous (){
Document. getElementById ("pollingtext"). value = getUrlParam ("text ");
}
Function Polling (){
Synchronous ();
SetInterval ("synchronous ()", 500 );
}
Script
I hope this article will help you design javascript programs.