サマリー:<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>郵箱登錄字段驗(yàn)證</titl
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>郵箱登錄字段驗(yàn)證</title> </head> <body> <h3>用戶登陸$.get()</h3> <p>郵箱:<input type="email" id="email" name="email"></p> <p>密碼:<input type="password" id="password" name="password"></p> <p><button>登陸</button></p> <script src="main/jquery-3.3.1.js"></script> <script> $('button').click(function(){ //郵箱的非空驗(yàn)證 if($('#email').val().length===0){ $('#email').after('<span style="color:red">郵箱不能為空</span>').next().fadeOut(2000); $('#email').focus();//設(shè)置焦點(diǎn) return false; } //密碼的非空驗(yàn)證 if($('#password').val().length===0){ $('#password').after('<span style="color:red">郵箱不能為空</span>').next().fadeOut(2000); $('#password').focus();//設(shè)置焦點(diǎn) return false; } //密碼長度不少于六位 if($('#password').val().length<6){ $('#password').after('<span style="color:red">密碼不能少于6位</span>').next().fadeOut(2000); $('#password').focus();//設(shè)置焦點(diǎn) return false; } $.get( //處理請求的腳本 'main/check.php', //要發(fā)送到服務(wù)器上的數(shù)據(jù) { eamil:$('#email').val(), password:$('#password').val() }, function(data){ console.log(data); }, //響應(yīng)數(shù)據(jù)的類型 'json' ); }) </script> </body> </html>
添削の先生:天蓬老師添削時(shí)間:2019-03-25 09:13:44
先生のまとめ:jquery 中的ajax操作是非常簡單的, 對比原生, 封裝了很多細(xì)節(jié), 多做幾個(gè)這樣的練習(xí)