2015-01-26 5 views
0

내가 basicly했던 것은 그 다음입니다 : HTML/PHP 양식 :JQuery와 입력 동적 확인

<html> 
 
    \t <head> 
 
    \t \t <link rel="stylesheet" type="text/css" href="gstyle.css"> 
 
    \t </head> 
 
    \t <body> 
 
    \t <script type="text/javascript" src="resources/jquery-1.11.2.min.js"></script> 
 
    \t <script type="text/javascript" src="resources/jquery-ui/jquery-ui.min.js"></script> 
 
    \t <script type="text/javascript" src="script.js"></script> 
 
    \t \t \t <form method="POST"> 
 
    \t \t \t \t <table border=0> 
 
    \t \t \t \t \t <tr> 
 
    \t \t \t \t \t \t <td class="descripcion">Usuario:</td> 
 
    \t \t \t \t \t \t <td><input class="campos" type="text" name="user" placeholder="Nombre de usuario"></td> 
 
    \t \t \t \t \t </tr> 
 
    \t \t \t \t \t <tr> 
 
    \t \t \t \t \t \t <td class="descripcion">Contraseña: 
 
    \t \t \t \t \t \t <td><input class="campos" type="password" name="passwd" placeholder="Contraseña"></td> 
 
    \t \t \t \t \t </tr> 
 
    \t \t \t \t \t <tr> 
 
    \t \t \t \t \t \t <td class="descripcion">Confirmar contraseña:</td> 
 
    \t \t \t \t \t \t <td><input class="campos" type="password" name="confpasswd" placeholder="Confirmar Contraseña"></td> 
 
    \t \t \t \t \t </tr> 
 
    \t \t \t \t \t <tr> 
 
    \t \t \t \t \t \t <td class="descripcion">Correo:</td> 
 
    \t \t \t \t \t \t <td><input class="campos" type="text" name="correo" placeholder="E-Mail"></td> 
 
    \t \t \t \t \t </tr> 
 
    \t \t \t \t \t <tr> 
 
    \t \t \t \t \t \t <td class="descripcion">Confirmar correo:</td> 
 
    \t \t \t \t \t \t <td><input class="campos" type="text" name="confcorreo" placeholder="Confirmar E-Mail"></td> 
 
    \t \t \t \t \t </tr> 
 
    \t \t \t \t </table> 
 
    \t \t \t \t <br> 
 
    \t \t \t \t <input class="botones" type="submit" name="send" value="Registrar"> 
 
       </form> 
 
     \t </div> 
 
    \t </body> 
 
    </html>

는 CSS 클래스와 간단한 regiter 처방집입니다. 에 클래스를 추가 한 후 몇 가지 입력을 평가하는 것입니다 objetive

#form { 
 
    \t font-family: Tahoma; 
 
    \t font-size: 20px; 
 
    \t margin-top: 200px; 
 
    \t margin-left: auto; 
 
    \t margin-right: auto; 
 
    \t padding: 20px 10px 20px 50px; 
 
    \t width: 700px; 
 
    \t text-align: center; 
 
    \t border-radius: 5px; 
 
    \t background: url("imagenes/div_fondo.jpg"); 
 
    \t background-size: cover; 
 
    \t background-position: center center; 
 
    \t background-repeat: no-repeat; 
 
    \t background-attachment:fixed; 
 
    \t -webkit-box-shadow: 10px 10px 15px 0px rgba(0,0,0,0.8); 
 
    \t -moz-box-shadow: 10px 10px 15px 0px rgba(0,0,0,0.8); 
 
    \t box-shadow: 10px 10px 15px 0px rgba(0,0,0,0.8); 
 
    } 
 

 
    #head { 
 
    \t color: white; 
 
    \t font-family: Tahoma; 
 
    \t font-size: 20px; 
 
    \t margin-top: 20px; 
 
    \t margin-left: auto; 
 
    \t margin-right: auto; 
 
    \t padding: 10px 0px 10px 0px; 
 
    \t width: 1500px; 
 
    \t text-align: center; 
 
    \t border-radius: 5px; 
 
    \t background: url("imagenes/div_fondo.jpg"); 
 
    \t background-size: cover; 
 
    \t background-position: center center; 
 
    \t background-repeat: no-repeat; 
 
    \t background-attachment:fixed; 
 
    \t text-shadow: 0px 0px 15px #2222FF; 
 
    \t -webkit-box-shadow: 10px 10px 15px 0px rgba(0,0,0,0.8); 
 
    \t -moz-box-shadow: 10px 10px 15px 0px rgba(0,0,0,0.8); 
 
    \t box-shadow: 10px 10px 15px 0px rgba(0,0,0,0.8); 
 
    } 
 

 
    td { 
 
    \t padding-top: 15px; 
 
    } 
 

 
    #titulo{ 
 
    \t text-shadow: 0px 0px 8px #2222FF; 
 
    \t line-height: 5px; 
 
    \t color: white; 
 
    } 
 

 
    .descripcion{ 
 
    \t text-shadow: 0px 0px 8px #2222FF; 
 
    \t color: white; 
 
    \t text-align:right; 
 
    \t font-size: 20px; 
 
    } 
 

 
    .campos{ 
 
    \t -webkit-box-shadow: inset 3px 3px 3px 0px rgba(0,0,0,0.78); 
 
    \t -moz-box-shadow: inset 3px 3px 3px 0px rgba(0,0,0,0.78); 
 
    \t box-shadow: inset 3px 3px 3px 0px rgba(0,0,0,0.78); 
 
     height: 40px; 
 
     margin: 15px; 
 
     padding: 12px; 
 
     width: 300px; 
 
     font-size: 18px; 
 
     border: 0; 
 
    \t border-radius: 3px; 
 
    } 
 

 
    .campos:focus { 
 
    \t -webkit-box-shadow: 0px 0px 13px 6px rgba(36,160,255,1); 
 
    \t -moz-box-shadow: 0px 0px 13px 6px rgba(36,160,255,1); 
 
    \t box-shadow: 0px 0px 13px 6px rgba(36,160,255,1); 
 
    } 
 

 
    .correcto{ 
 
    \t -webkit-box-shadow: 0px 0px 13px 6px rgba(0,255,81,1); 
 
    \t -moz-box-shadow: 0px 0px 13px 6px rgba(0,255,81,1); 
 
    \t box-shadow: 0px 0px 13px 6px rgba(0,255,81,1); 
 
    } 
 

 
    .incorrecto{ 
 
    \t -webkit-box-shadow: 0px 0px 13px 6px rgba(255,0,0,1); 
 
    \t -moz-box-shadow: 0px 0px 13px 6px rgba(255,0,0,1); 
 
    \t box-shadow: 0px 0px 13px 6px rgba(255,0,0,1); 
 
    } 
 

 
    .botones { 
 
    \t -webkit-box-shadow: 10px 10px 15px 0px rgba(0,0,0,0.8); 
 
    \t -moz-box-shadow: 10px 10px 15px 0px rgba(0,0,0,0.8); 
 
    \t box-shadow: 10px 10px 15px 0px rgba(0,0,0,0.8); 
 
    \t background-color:#7C1919; 
 
    \t width: 250px; 
 
    \t height: 50px; 
 
    \t border: 0; 
 
    \t font-size: 20px; 
 
    }
그리고 JQuery와 스크립트를 그런 다음 나는 또한 현재의 스타일과 정확하고 잘못된 JQuery와 준비 클래스와 CSS 시트가 사용자에게 그 정보가 맞는지 아닌지를 알려주는 입력이지만 동적 인 정보를 원한다. 즉, 페이지를 계속 충전하지 않고 입력을 지속적으로 평가하는 것이다.

$(document).ready(function(){ 
 
    \t var user = $("input[name=user]").val(); 
 
    \t if(user === "Vitama") { 
 
    \t \t $("input[name=user]").addClass("correcto"); 
 
    \t } 
 
    });

나는이 스크립트가 그 일을 할 것 suposed하지만, 내가 잘못했다. 일부 도움을주세요. 어떻게 동적으로 만들 수 있습니까?

+0

질문은 무엇입니까? 무슨 문제 있니? 코드를 게시했지만 문제를 충분히 설명하지 못하는 것이 좋습니다. – j08691

+0

문제는 필자가 한 일이 동적 인 동적 조합을 만들 것이라고 맹세했기 때문이며, 그렇지 않은 경우 유효성 검사를 위해 페이지를 다시로드해야했습니다. – Vitama

답변

1

jQuery에서 .keyup 기능을 찾고있는 것처럼 들립니다. 조건을 입력 할 때 평가합니다.

"correcto"속성에 !important 키워드를 추가하여 :focus 속성을 덮어 씁니다.

var user; 
 
$("input[name=user]").keyup(function() { 
 
    user = $("input[name=user]").val(); 
 
    if (user === "Vitama") { 
 
    $("input[name=user]").addClass("correcto"); 
 
    } 
 
});
#form { 
 
    font-family: Tahoma; 
 
    font-size: 20px; 
 
    margin-top: 200px; 
 
    margin-left: auto; 
 
    margin-right: auto; 
 
    padding: 20px 10px 20px 50px; 
 
    width: 700px; 
 
    text-align: center; 
 
    border-radius: 5px; 
 
    background: url("imagenes/div_fondo.jpg"); 
 
    background-size: cover; 
 
    background-position: center center; 
 
    background-repeat: no-repeat; 
 
    background-attachment: fixed; 
 
    -webkit-box-shadow: 10px 10px 15px 0px rgba(0, 0, 0, 0.8); 
 
    -moz-box-shadow: 10px 10px 15px 0px rgba(0, 0, 0, 0.8); 
 
    box-shadow: 10px 10px 15px 0px rgba(0, 0, 0, 0.8); 
 
} 
 
#head { 
 
    color: white; 
 
    font-family: Tahoma; 
 
    font-size: 20px; 
 
    margin-top: 20px; 
 
    margin-left: auto; 
 
    margin-right: auto; 
 
    padding: 10px 0px 10px 0px; 
 
    width: 1500px; 
 
    text-align: center; 
 
    border-radius: 5px; 
 
    background: url("imagenes/div_fondo.jpg"); 
 
    background-size: cover; 
 
    background-position: center center; 
 
    background-repeat: no-repeat; 
 
    background-attachment: fixed; 
 
    text-shadow: 0px 0px 15px #2222FF; 
 
    -webkit-box-shadow: 10px 10px 15px 0px rgba(0, 0, 0, 0.8); 
 
    -moz-box-shadow: 10px 10px 15px 0px rgba(0, 0, 0, 0.8); 
 
    box-shadow: 10px 10px 15px 0px rgba(0, 0, 0, 0.8); 
 
} 
 
td { 
 
    padding-top: 15px; 
 
} 
 
#titulo { 
 
    text-shadow: 0px 0px 8px #2222FF; 
 
    line-height: 5px; 
 
    color: white; 
 
} 
 
.descripcion { 
 
    text-shadow: 0px 0px 8px #2222FF; 
 
    color: white; 
 
    text-align: right; 
 
    font-size: 20px; 
 
} 
 
.campos { 
 
    -webkit-box-shadow: inset 3px 3px 3px 0px rgba(0, 0, 0, 0.78); 
 
    -moz-box-shadow: inset 3px 3px 3px 0px rgba(0, 0, 0, 0.78); 
 
    box-shadow: inset 3px 3px 3px 0px rgba(0, 0, 0, 0.78); 
 
    height: 40px; 
 
    margin: 15px; 
 
    padding: 12px; 
 
    width: 300px; 
 
    font-size: 18px; 
 
    border: 0; 
 
    border-radius: 3px; 
 
} 
 
.campos:focus { 
 
    -webkit-box-shadow: 0px 0px 13px 6px rgba(36, 160, 255, 1); 
 
    -moz-box-shadow: 0px 0px 13px 6px rgba(36, 160, 255, 1); 
 
    box-shadow: 0px 0px 13px 6px rgba(36, 160, 255, 1); 
 
} 
 
.correcto { 
 
    -webkit-box-shadow: 0px 0px 13px 6px rgba(0, 255, 81, 1)!important; 
 
    -moz-box-shadow: 0px 0px 13px 6px rgba(0, 255, 81, 1)!important; 
 
    box-shadow: 0px 0px 13px 6px rgba(0, 255, 81, 1)!important; 
 
} 
 
.incorrecto { 
 
    -webkit-box-shadow: 0px 0px 13px 6px rgba(255, 0, 0, 1); 
 
    -moz-box-shadow: 0px 0px 13px 6px rgba(255, 0, 0, 1); 
 
    box-shadow: 0px 0px 13px 6px rgba(255, 0, 0, 1); 
 
} 
 
.botones { 
 
    -webkit-box-shadow: 10px 10px 15px 0px rgba(0, 0, 0, 0.8); 
 
    -moz-box-shadow: 10px 10px 15px 0px rgba(0, 0, 0, 0.8); 
 
    box-shadow: 10px 10px 15px 0px rgba(0, 0, 0, 0.8); 
 
    background-color: #7C1919; 
 
    width: 250px; 
 
    height: 50px; 
 
    border: 0; 
 
    font-size: 20px; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
 

 
<body> 
 
    <form method="POST"> 
 
    <table border=0> 
 
     <tr> 
 
     <td class="descripcion">Usuario:</td> 
 
     <td> 
 
      <input class="campos" type="text" name="user" placeholder="Nombre de usuario"> 
 
     </td> 
 
     </tr> 
 
     <tr> 
 
     <td class="descripcion">Contraseña: 
 
      <td> 
 
      <input class="campos" type="password" name="passwd" placeholder="Contraseña"> 
 
      </td> 
 
     </tr> 
 
     <tr> 
 
     <td class="descripcion">Confirmar contraseña:</td> 
 
     <td> 
 
      <input class="campos" type="password" name="confpasswd" placeholder="Confirmar Contraseña"> 
 
     </td> 
 
     </tr> 
 
     <tr> 
 
     <td class="descripcion">Correo:</td> 
 
     <td> 
 
      <input class="campos" type="text" name="correo" placeholder="E-Mail"> 
 
     </td> 
 
     </tr> 
 
     <tr> 
 
     <td class="descripcion">Confirmar correo:</td> 
 
     <td> 
 
      <input class="campos" type="text" name="confcorreo" placeholder="Confirmar E-Mail"> 
 
     </td> 
 
     </tr> 
 
    </table> 
 
    <br> 
 
    <input class="botones" type="submit" name="send" value="Registrar"> 
 
    </form> 
 
    </div> 
 
</body>