Total Java Learning (26)--javascript regular expression, JS form validation, native JS+CSS page clock

Source: Internet
Author: User
Tags getdate

A JavaScript Regular Expressions
1.EXEC retrieves the value specified in the string, returns the found value, and determines its location
2.test retrieves the value specified in the string, returning True or false
3. Creation of regular expression objects:
(1) Mode one:
Var rgex=new RegExp ("[0-9]", "mode");
(2) Way two: simple notation, with double slash//to enclose the contents of regular expressions
Example 1 (regular creation, using the test () method):

<!DOCTYPE html>

Operation Result:

Two JavaScript completes form validation
1. Start by understanding several related events:
(1) The Commit event value of the OnSubmit form is the return true form can be submitted to the background
(2) onblur form loses focus
2. Code examples to illustrate form validation:

<! DOCTYPE html>

Running results show:
1. Initial interface:

2. Form validation (Error input):

3. Reset the display:

4. Form validation is entered correctly (click to register is not selected in the box):

5. Single-Verify the correct input (single box check click Register):

Jump:

Three Display of the page clock
1. The basic idea is to update the current time every second
2. Simple code:

<!DOCTYPE html>

Operation Result:

Second time:

3. Reference code:
Address Link: https://www.cnblogs.com/syp172654682/p/7588104.html
It's very well written, and it's borrowed.
Reference Code replication:
External CSS Code:

 /* Global */* {margin:0; padding:0; }. clock {width:400px; height:400px; border:10px solid #333; box-shadow:0px 0px 20px 3px #444 inset; border-radius:210px; position:relative; MARGIN:5PX Auto; Z-index:10; Background-color: #f6f6f6; }/* Clock number */. clock-num {width:40px; height:40px; font-size:22px; Text-align:center; line-height:40px; Position:absolute; Z-index:8; Color: #555; Font-family:fantasy, ' trebuchet MS '; }. em_num {font-size:28px;}/* pointer */. clock-line {position:absolute; z-index:20; }. hour-line {width:100px; height:4px; top:198px; left:200px; Background-color: #000; border-radius:2px; Transform-origin:0 50%; box-shadow:1px-3px 8px 3px #aaa; }. minute-line {width:130px; height:2px; top:199px; left:190px; Background-color: #000; transform-origin:7.692% 50%; box-shadow:1px-3px 8px 1px #aaa; }. second-line {width:170px; height:1px; top:199.5px; left:180px; Background-color: #f60; transform-origin:11.765% 50%; box-shadow:1px-3px 7px 1px #bbb; }/* Origin point */. Origin {width:20px; height:20px; border-radius:10px; Background-color: #000; Position:absolute; top:190px; left:190px; z-index:14; }/* Date time */. date-info {width:160px; height:28px; line-height:28px; Text-align:center; Position:absolute; top:230px; left:120px; Z-index:11; Color: #555; Font-weight:bold; font-family: ' Microsoft ya Black '; }. time-info {width:92px; height:30px; line-height:30px; Text-align:center; Position:absolute; top:270px; left:154px; Z-index:11; Background-color: #555; padding:0; box-shadow:0px 0px 9px 2px #222 inset; }. Time {width:30px; height:30px; Text-align:center; Float:left; Color: #fff; Font-weight:bold; } #minute-time {border-left:1px solid #fff; border-right:1px soLid #fff; }/* scale */. clock-scale {width:195px; height:2px; transform-origin:0% 50%; Z-index:7; Position:absolute; top:199px; left:200px; }. scale-show {width:12px; height:2px; Background-color: #555; Float:left; }. scale-hidden {width:183px; height:2px; Float:left; }

External JS code:

(function () {window.onload = Initnumxy (200, 160, 40, 40);    var hour_line = document.getElementById ("Hour-line");    var minute_line = document.getElementById ("Minute-line");    var second_line = document.getElementById ("Second-line");    var date_info = document.getElementById ("Date-info");    var week_day = [' Sunday ', ' Monday ', ' Tuesday ', ' Wednesday ', ' Thursday ', ' Friday ', ' Saturday '];    var hour_time = document.getElementById ("Hour-time");    var minute_time = document.getElementById ("Minute-time");    var second_time = document.getElementById ("Second-time");        function settime () {var this_day = new Date ();            var hour = (This_day.gethours () >= 12)?        (This_day.gethours ()--): This_day.gethours ();        var minute = This_day.getminutes ();        var second = This_day.getseconds ();        var hour_rotate = (Hour * 30-90) + (Math.floor (MINUTE/12) * 6);        var year = This_day.getfullyear ();            var month = ((This_day.getmonth () + 1) < 10)? "0 "+ (this_day.getmonth () + 1): (This_day.getmonth () + 1);            var date = (This_day.getdate () < 10)?        "0" + this_day.getdate (): This_day.getdate ();        var day = This_day.getday ();        Hour_line.style.transform = ' rotate (' + hour_rotate + ' deg) ';        Minute_line.style.transform = ' rotate (' + (minute * 6-90) + ' deg ');        Second_line.style.transform = ' rotate (' + (second * 6-90) + ' deg ');        date_info.innerhtml = year + "-" + month + "-" + date + "+ Week_day[day];            hour_time.innerhtml = (this_day.gethours () < 10)?        "0" + this_day.gethours (): This_day.gethours ();            minute_time.innerhtml = (this_day.getminutes () < 10)?        "0" + this_day.getminutes (): This_day.getminutes ();            second_time.innerhtml = (This_day.getseconds () < 10)?    "0" + this_day.getseconds (): This_day.getseconds ();    } setinterval (settime, 1000);       function Initnumxy (R, R, W, h) {var numxy = [{     "Left": R + 0.5 * r-0.5 * W, "top": R-0.5 * R * 1.73205-0.5 * H}, {"Left": R + 0            .5 * R * 1.73205-0.5 * W, "top": R-0.5 * r-0.5 * H}, {"Left": R + r-0.5 * W, "Top": R-0.5 * H}, {"Left": R + 0.5 * r * 1.73205-0.5 * W, "top": r + 0.5 * r-0.            5 * H}, {"Left": R + 0.5 * r-0.5 * W, "top": R + 0.5 * r * 1.732-0.5 * H}, {            "Left": R-0.5 * W, "top": R + r-0.5 * H}, {"Left": R-0.5 * r-0.5 * W, "Top": R + 0.5 * r * 1.732-0.5 * H}, {"Left": R-0.5 * R * 1.73205-0.5 * W, "to            P ": R + 0.5 * r-0.5 * H}, {" Left ": r-r-0.5 * W," top ": R-0.5 * H}, { "Left": R-0.5 * R * 1.73205-0.5 * w, ' top ': R-0.5 * r-0.5 * H}, {"Left": R-0       .5 * r-0.5 * W,     "Top": R-0.5 * R * 1.73205-0.5 * H}, {"Left": R-0.5 * W, "top": r-r-0.5 * H        }];        var clock = document.getElementById ("clock"); for (var i = 1; i <=; i++) {if (i% 3 = = 0) {clock.innerhtml + = "<div class= ' Clock-nu            M em_num ' > "+ i +" </div> ";            } else {clock.innerhtml + = "<div class= ' Clock-num ' >" + i + "</div>";        }} var clock_num = Document.getelementsbyclassname ("Clock-num");            for (var i = 0; i < clock_num.length; i++) {clock_num[i].style.left = numxy[i].left + ' px ';        Clock_num[i].style.top = numxy[i].top + ' px ';                } for (var i = 0; i < i++) {clock.innerhtml + = "<div class= ' Clock-scale ' >" +                "<div class= ' Scale-hidden ' ></div>" + "<div class= ' scale-show ' ></div>" +     "</div>";   } var scale = Document.getelementsbyclassname ("Clock-scale");        for (var i = 0; i < scale.length; i++) {scale[i].style.transform = "rotate (" + (I * 6-90) + "deg)"; }    }})();

HTML code:

<!doctype html>

Operation Result:

 【总结完毕】

Total Java Learning (26)--javascript regular expression, JS form validation, native JS+CSS page clock

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.