当登录到网站时凭据错误时,jquery突出显示输入框

当登录到网站时凭据错误时,jquery突出显示输入框,jquery,html,forms,login,Jquery,Html,Forms,Login,我不确定为什么我不能像在我的JSFIDLE中那样让它正常工作: 也许是因为我的帖子是指向另一个页面的?也许它真的起作用了,但是因为url的改变,我没有看到它 <script> $('#loginForm').submit(function(){ var vals = $('.nomargin').val() if (!vals) { console.log('Error exists'); $('.

我不确定为什么我不能像在我的JSFIDLE中那样让它正常工作:

也许是因为我的帖子是指向另一个页面的?也许它真的起作用了,但是因为url的改变,我没有看到它

<script> 


$('#loginForm').submit(function(){
     var vals = $('.nomargin').val()
     if (!vals) 
        {
          console.log('Error exists');
          $('.nomargin').attr('style', "border-radius: 5px; border:#FF0000 1px solid;");
          $('.nomargin').val('enter a value');
        }  
    return false;
});        
</script> 

        <div class="loginBox clearMeFocus">
                <form action="client_homepage.dhtml" method="post" name="loginForm" id="loginForm" >

<input type="hidden" name="site" id="site" value="free">

                    <h3>Agent Log In</h3>
                    <div style="float: left; font-size: 10px; color: red; margin-top: -8px; position: absolute;"></div>
                    <div class="clearfix">
                        <input type="text" name="username" id="username" value="" title="username" class="nomargin">
                        <input type="password" name="password" id="password" value="" title="password">
                        <input type="image" src="images/submit.png" value="submit" name="submit" id="submit" alt="submit">
                    </div>
                    <h6><a href="/join.dhtml">Not an Associate?</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="/password.html">Forgot Password?</a></h6>
                </form>
            </div>

$('#loginForm')。提交(函数(){
var val=$('.nomargin').val()
如果(!VAL)
{
log('Error exists');
$('.nomargin').attr('style',“边框半径:5px;边框:#FF0000 1px solid;”);
$('.nomargin').val('输入值');
}  
返回false;
});        
代理登录

任何帮助都将不胜感激。谢谢。

您在条件之外返回false,因此表单将永远不会提交,请按如下方式更新:

$('#submit_form').submit(function(){
     var vals = $('.validate').val()
     if (vals == '') //changed this from !val to == ''
        {
          console.log('Error exists');
          $('.validate').attr('style', "border-radius: 5px; border:#FF0000 1px solid;");
          $('.validate').val('enter a value');
        }  
    return false;
});
$('#loginForm').submit(function(){
 var vals = $('.nomargin').val()
 if (!vals || vals=="") 
    {
      console.log('Error exists');
      $('.nomargin').attr('style', "border-radius: 5px; border:#FF0000 1px solid;");
      $('.nomargin').val('enter a value');
        return false;
    }  
});    

检查此项

不起作用。。但可能是因为我需要添加
$(document).ready(function)
??使用“Try{”时,您是否打算使用
Try
关键字..?如果不是,您应该删除
{
block之后,为了避免混淆,我仍然无法让它工作,我觉得这是因为当我提交时,即使它是错误的,它也会更改页面。@cookinggood P.s即使输入了正确的值,您原来的小提琴也不会工作,因为您的提交函数总是返回false。如果失败,它不会突出显示它登录失败。htmlet-us