Bacaan terkait:
Berdasarkan jQuery, fungsi hitung mundur setelah mengirim kode verifikasi SMS direalisasikan (mengabaikan halaman dan tutup)
Kode berikut adalah kode yang dibawa editor kepada Anda setelah mengirim kode verifikasi SMS kepada Anda. Kode ini sederhana dan mudah dimengerti.
Kode spesifiknya adalah sebagai berikut:
<!doctype html><html lang="en"><head><meta charset="UTF-8"><meta name="Generator" content="EditPlus®"><meta name="Author" content=""><meta name="Keywords" content=""><meta name="Description" content=""><title>Document</title><script src = "http://cdn.bootcss.com/jquery/3.1.0/jquery.js"> </script> <script src = "http://cdn.bootcss.com/jquery-cookie/1.4.1/jquery.cookie.js"> </skrip/skrip src = "// cdn.bootcss.com/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>--></head><body><input id =" phonenum "type =" text "value =" 1851818181818 "/<input" type = "text" value = "18518181818"/<input iD = "Text" value = "18518181818"/<input = "" Text "Nilai =" 18518181818 " /> </body> <script> // tambahkan fungsi saat mengirim kode verifikasi addCookie (nama, nilai, ekspirasi) {// menilai apakah akan mengatur waktu kedaluwarsa, 0 berarti tidak valid saat menutup browser if (excireshours> 0) {var tanggal = tanggal baru (); date.settime (date.getTime ()+Expireshours*1000); $ .cookie (name, Escape (value), {Expires: date});} else {$. cookie (name, Escape (value));}} // Ubah nilai fungsi cookie editCookie (name, value, expirhours) {if (expirourours> 0) {var date = new date (); date.settime (date.getTime ()+Expireshours*1000); //The unit is milliseconds$.cookie(name, escape(value), {expires: date});} else{$.cookie(name, escape(value));}} //Get the value of the cookie based on the name function getCookieValue(name){ return $.cookie(name);}$(function(){$("#second").click(function (){sendCode($("#second"));});v = getCookieValue("secondsremained");//Get the cookie value if(v>0){settime($("#second"));//Start countdown}})//Send verification code function sendCode(obj){var phonenum = $("#phonenum").val();var result = isphonenum (); if (hasil) {// dopostback ('$ {base} /login/getcode.htm',backfunc1, {"phonenum": phonenum}); addCookie ("countdown second -countdown (60,60); // Tambahkan catatan cookie, start -time 60 varifdown (countdown (secondSremained", 60,60);//Tambah cookie record, time countdown ("countdown (countdown (secondsremained", 60,60);//Tambah cookie record, time countdown 60 VARICEDDOWNDIND (COUNTDINDIDDOWDIND (COUNTDIND (COUNTDIND; function setTime (OBJ) {Countdown = getCookievalue ("SecondSremained"); if (countDown == 0) {obj.removeattr ("Disable"); obj.val ("Kode verifikasi mendapatkan gratis"); return;} else {obj.attr ("dinonaktifkan", true); obj.val ("Resend (" + Countdown + ")"); countdown--;editCookie("secondsremained",countdown,countdown+1);} setTimeout(function() { settime(obj) },1000) //Execute every 1000 milliseconds} //Check whether the phone number is legal function isPhoneNum(){var phonenum = $("#phonenum").val();var myreg = /^(((13 [0-9] {1}) | (15 [0-9] {1}) | (18 [0-9] {1}))+/d {8}) $/; if (! myreg.test (phonenum)) {alert ('Harap masukkan nomor ponsel yang valid!'); mengembalikan false; } else {return true;}} </script> </html>Di atas adalah fungsi hitung mundur setelah mengirim kode verifikasi SMS berdasarkan JS yang diperkenalkan oleh editor (mengabaikan refresh halaman, halaman ditutup dan fungsi hitung mundur tidak dilakukan). Saya harap ini akan membantu semua orang. Jika Anda memiliki pertanyaan, silakan tinggalkan saya pesan dan editor akan membalas semua orang tepat waktu. Terima kasih banyak atas dukungan Anda ke situs web Wulin.com!