0

我有一个表格,当我这样输入时:

<form name="formLogin" id="formLogin" action="index.aspx" method="post">

我的 javascript 工作正常,网页的源代码与上面列出的相同。

当我这样输入时:

<form name="formLogin" id="formLogin" runat="server">

我的页面崩溃了。我基本上正在使用第三方模板并尝试将其转换为 asp.net。

显示的源代码是这样的:

<form id="formLogin" action="index.aspx" method="post">

似乎当我使用该runat="server"选项时,它会重新创建没有名称的表单元素?我必须在 .net 上使用runtat="server"if 并且想要处理 Jquery 和服务器端验证吗?

如果我不包含runat="Server"?

      $(document).ready(function () {     
            onfocus();
            $(".on_off_checkbox").iphoneStyle();
            $('.tip a ').tipsy({gravity: 'sw'});
            $('#login').show().animate({   opacity: 1 }, 2000);
            $('.logo').show().animate({   opacity: 1,top: '30%'}, 800,function(){           
                $('.logo').show().delay(1200).animate({   opacity: 1,top: '0%' }, 300,function(){
                    $('.formLogin').animate({   opacity: 1,left: '0' }, 300);
                    $('.userbox').animate({ opacity: 0 }, 200).hide();
                 });        
            })  
        }); 

        $('.userload').click(function(e){
            $('.formLogin').animate({   opacity: 1,left: '0' }, 300);               
              $('.userbox').animate({ opacity: 0 }, 200,function(){
                  $('.userbox').hide();             
               });
        });

    $('#but_login').click(function(e){              
          if(document.formLogin.username.value == "" || document.formLogin.password.value == "") // BREAKS HERE
          {
              showError("Please Input Username / Password");
              $('.inner').jrumble({ x: 4,y: 0,rotation: 0 });   
              $('.inner').trigger('startRumble');
              setTimeout('$(".inner").trigger("stopRumble")',500);
              setTimeout('hideTop()',5000);
              return false;
          }     
         hideTop();
         loading('Checking',1);     
         setTimeout( "unloading()", 2000 );
         setTimeout( "Login()", 2500 );
    }); 

function Login(){
    $("#login").animate({   opacity: 1,top: '49%' }, 200,function(){
         $('.userbox').show().animate({ opacity: 1 }, 500);
            $("#login").animate({   opacity: 0,top: '60%' }, 500,function(){
                $(this).fadeOut(200,function(){
                  $(".text_success").slideDown();
                  $("#successLogin").animate({opacity: 1,height: "200px"},500);                  
                });                           
             }) 
     }) 
    setTimeout( "window.location.href='dashboard.html'", 3000 );
}

$('#alertMessage').click(function(){
    hideTop();
});

function showError(str){
    $('#alertMessage').addClass('error').html(str).stop(true,true).show().animate({ opacity: 1,right: '0'}, 500);   

}

function showSuccess(str){
    $('#alertMessage').removeClass('error').html(str).stop(true,true).show().animate({ opacity: 1,right: '0'}, 500);    
}

function onfocus(){
                if($(window).width()>480) {                   
                        $('.tip input').tipsy({ trigger: 'focus', gravity: 'w' ,live: true});
                }else{
                      $('.tip input').tipsy("hide");
                }
}

function hideTop(){
    $('#alertMessage').animate({ opacity: 0,right: '-20'}, 500,function(){ $(this).hide(); });  
}   

function loading(name,overlay) {  
      $('body').append('<div id="overlay"></div><div id="preloader">'+name+'..</div>');
              if(overlay==1){
                $('#overlay').css('opacity',0.1).fadeIn(function(){  $('#preloader').fadeIn();  });
                return  false;
         }
      $('#preloader').fadeIn();   
 }

 function unloading() {  
        $('#preloader').fadeOut('fast',function(){ $('#overlay').fadeOut(); });
 }
4

1 回答 1

1

如果您不runat=Server这样做,您将无法访问实际表单/任何未在代码后面(服务器端)中标记 runat=server 的控件。请发布您的 jquery 代码,如果我看到一些奇怪的东西,我可以编辑这个答案。

使用$("#username").val().length和 相同的密码来查看名称/密码是否存在。您混合了 js 和 jquery,这使得找到罪魁祸首变得更加困难。

if($("#username").val().length == 0 && $("#password").val().length == 0)

  //enter here if one is missing
于 2012-04-12T19:25:16.683 回答