{"id":1936,"date":"2023-03-25T14:26:38","date_gmt":"2023-03-25T06:26:38","guid":{"rendered":""},"modified":"2023-03-25T14:26:38","modified_gmt":"2023-03-25T06:26:38","slug":"ES6 \u9a8c\u8bc1","status":"publish","type":"post","link":"https:\/\/bianchenghao6.com\/1936.html","title":{"rendered":"ES6 \u9a8c\u8bc1"},"content":{"rendered":"


\n <\/head>
\n <\/p>\n

\n

ES6 \u9a8c\u8bc1<\/h1>\n<\/p><\/div>\n

ES6 Validations<\/h2>\n
\n Validation \u662f\u6839\u636e\u8981\u6c42\u68c0\u67e5\u524d\u7aef\u7528\u6237\u63d0\u4f9b\u7684\u4fe1\u606f\u662f\u5426\u6b63\u786e\u7684\u8fc7\u7a0b\u3002\u5982\u679c\u5ba2\u6237\u7aef\u63d0\u4f9b\u7684\u6570\u636e\u4e0d\u6b63\u786e\u6216\u4e22\u5931\uff0c\u5219\u670d\u52a1\u5668\u5fc5\u987b\u5c06\u8be5\u6570\u636e\u53d1\u9001\u56de\u5ba2\u6237\u7aef\u5e76\u8bf7\u6c42\u91cd\u65b0\u63d0\u4ea4\u5177\u6709\u6b63\u786e\u4fe1\u606f\u7684\u8868\u5355\u3002\n <\/div>\n
\n \u901a\u5e38\uff0c\u9a8c\u8bc1\u8fc7\u7a0b\u5df2\u5b8c\u6210\u5728\u670d\u52a1\u5668\u7aef\uff0c\u5b83\u5c06\u9a8c\u8bc1\u4fe1\u606f\u53d1\u9001\u7ed9\u524d\u7aef\u7528\u6237\u3002\u8fd9\u4e2a\u8fc7\u7a0b\u6d6a\u8d39\u4e86\u6267\u884c\u65f6\u95f4\u548c\u7528\u6237\u65f6\u95f4\u3002\n <\/div>\n
\n JavaScript \u4e3a\u6211\u4eec\u63d0\u4f9b\u4e86\u4e00\u79cd\u9a8c\u8bc1\u8868\u5355\u7684\u65b9\u6cd5\u5728\u5c06\u6570\u636e\u53d1\u9001\u5230\u670d\u52a1\u5668\u7aef\u4e4b\u524d\u3002\u8868\u5355\u4e2d\u7684\u9a8c\u8bc1\u4e00\u822c\u6267\u884c\u4e24\u4e2a\u529f\u80fd\uff0c\u5206\u522b\u662f:\n <\/div>\n

\u57fa\u672c\u9a8c\u8bc1- \u8fd9\u662f\u4e00\u4e2a\u786e\u4fdd\u6240\u6709\u5fc5\u586b\u5b57\u6bb5\u90fd\u5df2\u586b\u5199\u6216\u672a\u586b\u5199\u7684\u8fc7\u7a0b\u3002 <\/span>
\n \u6570\u636e\u683c\u5f0f\u9a8c\u8bc1- \u987e\u540d\u601d\u4e49\uff0c\u5c31\u662f\u68c0\u67e5\u8f93\u5165\u7684\u6570\u636e\u662f\u5426\u6b63\u786e\u7684\u8fc7\u7a0b\u3002\u6211\u4eec\u5fc5\u987b\u5305\u542b\u9002\u5f53\u7684\u903b\u8f91\u6765\u6d4b\u8bd5\u6570\u636e\u7684\u6b63\u786e\u6027\u3002<\/span> <\/p>\n

\n \u8ba9\u6211\u4eec\u5c1d\u8bd5\u8be6\u7ec6\u8bf4\u660e\u57fa\u672c\u8868\u5355\u9a8c\u8bc1\u548c\u6570\u636e\u683c\u5f0f\u9a8c\u8bc1\u3002\n <\/div>\n

\u57fa\u672c\u8868\u5355\u9a8c\u8bc1<\/h2>\n
\n \u5b83\u9a8c\u8bc1\u5fc5\u586b\u8f93\u5165\u5b57\u6bb5\n <\/div>\n
\n \u8ba9\u6211\u4eec\u901a\u8fc7\u4e0b\u9762\u7684\u4f8b\u5b50\u6765\u4e86\u89e3\u57fa\u672c\u7684\u8868\u5355\u9a8c\u8bc1\u8fc7\u7a0b\u3002\n <\/div>\n
\n \u4f8b\u5b50\n <\/div>\n
\n
\n<!DOCTYPE html> \n<html> \n  \n<head> \n    <title>Example of Basic form Validation<\/title> \n    <script> \n        function validateBasic() { \n            var <\/span>name1 = document.basic.name.value; \n            var <\/span>qual1 = document.basic.qual.value;             \n            var <\/span>phone1 = document.basic.phone.value;  \n            if <\/span>(name1 == \"\"<\/span><\/span><\/span>) { \n             alert(\"Name required\"<\/span>);\n                return <\/span>false;   \n            } \n            if <\/span>(qual1 == \"\") { \n             alert(\"Qualification required\"<\/span>);\n                return <\/span>false;   \n            } \n            if <\/span>(phone1 == \"\") { \n             alert(\"Mobile number is required\"<\/span>);\n                return <\/span>false;   \n            } \n        } \n    <\/script> \n<\/head> \n  \n<body> \n    <center> \n        <h1>Basic Form Validation<\/h1>  \n        <form name=\"basic\"<\/span> action=\"#\"<\/span> onsubmit=\"return <\/span>validateBasic()\"<\/span>> <\/span>\n            <table cellspacing = \"2\"<\/span><\/span> cellpadding = \"2\" border = \"1\"<\/span>>\n            <tr>\n                <td>Name: <\/td>\n                <td><input type=\"text\"<\/span><\/span><\/span> name=\"name\"<\/span>><\/td>\n            <tr>\n            <tr>\n               <td> Qualification: <\/td>\n               <td><input type=\"text\" name=\"qual\"<\/span>><\/td>\n            <\/tr>\n            <tr>\n                <td>Phone no.:<\/td>\n                <td><input type=\"text\" name=\"phone\"<\/span>><\/td>\n            <\/tr>\n        <\/table>\n        <input type=\"submit\"<\/span> value=\"Submit\"<\/span>>\n    <\/form> \n       <p id=\"d1\"<\/span>><\/p> \n    <\/center> \n<\/body> \n  \n<\/html><\/pre>\n

<\/code>\n <\/div>\n

\u6570\u636e\u683c\u5f0f\u9a8c\u8bc1<\/h2>\n
\n \u5728\u6570\u636e\u683c\u5f0f\u9a8c\u8bc1\u4e2d\uff0c\u68c0\u67e5\u8f93\u5165\u7684\u6570\u636e\u662f\u5426\u6b63\u786e\u3002\u5b83\u4f1a\u9a8c\u8bc1\u5df2\u586b\u5199\u7684\u8f93\u5165\u5b57\u6bb5\u662f\u5426\u6b63\u786e\u3002\n <\/div>\n
\n \u8ba9\u6211\u4eec\u901a\u8fc7\u4ee5\u4e0b\u793a\u4f8b\u4e86\u89e3\u6570\u636e\u683c\u5f0f\u9a8c\u8bc1\u7684\u6982\u5ff5\u3002\n <\/div>\n
\n \u793a\u4f8b\n <\/div>\n
\n
\n<!DOCTYPE html> \n<html> \n  \n<head> \n    <title>Example of Basic form Validation<\/title> \n    <script> \n        function validateBasic() { \n            var <\/span>name1 = document.basic.name.value; \n            var <\/span>qual1 = document.basic.qual.value;             \n            var <\/span>phone1 = document.basic.phone.value;  \n            var <\/span>id = document.basic.em.value;   \n            if <\/span>(name1 == \"\"<\/span><\/span><\/span>) { \n             alert(\"Name required\"<\/span>);\n                return <\/span>false;   \n            } \n            if(name1.length<5){\n                alert(\"Username should be atleast 5 characters\"<\/span>);\n                return <\/span>false;\n            }\n            at = id.indexOf<\/span>(\"@\"<\/span>);    \n         dot = id.lastIndexOf<\/span>(\".\"<\/span>);    \n         \n         if <\/span>(at < 1 ||<\/span><\/span> ( dot-at < 2 )) {       \n            alert(\"Incorrect Email-ID\"<\/span>)         \n            return <\/span>false;    \n         }     \n            if <\/span>(qual1 == \"\") { \n             alert(\"Qualification required\"<\/span>);\n                return <\/span>false;   \n            } \n            if <\/span>(phone1 == \"\") { \n             alert(\"Mobile number is required\"<\/span>);\n                return <\/span>false;   \n            } \n            if(phone1.length<10 || phone1.length>10){\n                alert(\"Mobile number should be of 10 digits\"<\/span>);\n                return <\/span>false;\n            }\n \n        } \n <\/script> \n<\/head> \n  \n<body> \n    <center> \n        <h1>Basic Form Validation<\/h1>  \n        <form name=\"basic\"<\/span> action=\"#\"<\/span> onsubmit=\"return <\/span>validateBasic()\"<\/span>> <\/span>\n            <table cellspacing = \"2\"<\/span><\/span> cellpadding = \"2\" border = \"1\"<\/span>>\n            <tr>\n                <td>Name: <\/td>\n                <td><input type=\"text\"<\/span><\/span> name=\"name\"<\/span>><\/td>\n            <\/tr>\n                <tr>\n                    <td>Email: <\/td>\n               <td><input type=\"email\"<\/span> name=\"em\"<\/span>><\/td>\n                <\/tr>\n            \n            <tr>\n               <td> Qualification: <\/td>\n               <td><input type=\"text\" name=\"qual\"<\/span>><\/td>\n            <\/tr>\n            <tr>\n                <td>Phone no.:<\/td>\n                <td><input type=\"number\"<\/span> name=\"phone\"<\/span>><\/td>\n            <\/tr>\n        <\/table>\n        <input type=\"submit\"<\/span> value=\"Submit\"<\/span>>\n    <\/form> \n       <p id=\"d1\"<\/span>><\/p> \n    <\/center> \n<\/body> \n  \n<\/html><\/pre>\n

<\/code>\n <\/div>\n

<\/body>
\n<\/html><\/p>\n","protected":false},"excerpt":{"rendered":"ES6 \u9a8c\u8bc1zh-cn","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[161],"tags":[],"class_list":["post-1936","post","type-post","status-publish","format-standard","hentry","category-es6jc"],"_links":{"self":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/1936"}],"collection":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/comments?post=1936"}],"version-history":[{"count":0,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/1936\/revisions"}],"wp:attachment":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/media?parent=1936"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/categories?post=1936"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/tags?post=1936"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}