Rumah > hujung hadapan web > tutorial js > Melaksanakan pengesahan penyerahan borang berdasarkan jQuery_jquery

Melaksanakan pengesahan penyerahan borang berdasarkan jQuery_jquery

WBOY
Lepaskan: 2016-05-16 16:30:34
asal
1377 orang telah melayarinya

kod borang html:

Salin kod Kod adalah seperti berikut:

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          


Kod jQuery:




Salin kod


Kod adalah seperti berikut:

             $(fungsi(){
               $("borang :input.diperlukan").setiap(fungsi(){
              var $required = $("*"); //$(this).parent().append($required); //Lampirkan pada dokumen
                      $(this).parent().prepend($required);               });
                 $('form :input').blur(function(){
              var $parent = $(this).parent(); If($(this).is('#username')){
Jika(this.value==""||this.value.length<6){
                                                                                                                                                                                                                                                         var errorMsg = 'Sila masukkan nama pengguna sekurang-kurangnya 6 aksara';                                      $parent.append('' errorMsg '');
                           }lain{
                                                                                                                                                                                                                                                                                                                                                                                                                                                                              var okMsg = 'Input yang betul'; $parent.append('' okMsg '');                                                                                                                                                                                                                                                                                                                                                                                                                       If($(this).is('#email')){
if(this.value==""||(this.value!=""
&&!/. @. .[a-zA-Z]{2,4}$/.test(this.value
))){
                                var errorMsg = 'Sila masukkan alamat e-mel yang betul'
$parent.append('' errorMsg '');                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        '
                                       $parent.append('' okMsg '');                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   });
                $("bentuk :input").fokus(fungsi(){
              var $parent = $(this).parent();                        $parent.find(".formtips").remove();
              });                   $("#send").klik(function(){               var $parent = $(this).parent().parent();
                     $parent.find(".formtips").remove();
                      $("form .required:input").trigger('blur');               var numError = $('form .onError').panjang; If(numError){
                          kembali palsu;                                                                                                   });
                 $("#res").klik(function(){
              var $parent = $(this).parent().parent();
                       $parent.find(".formtips").remove();
              });
});



Kod ini sangat ringkas dan mudah difahami Rakan, cuma ambil dan gunakannya, saya tidak akan menerangkannya secara terperinci di sini.
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan