2012-08-30 2 views
0

입력을 입력하면 텍스트 상자에 다시 표시되며 수정 방법을 모르겠습니다. 다음은 출력의 스크린 샷입니다 :텍스트 상자에 다시 흐려짐 이벤트가 발생한 후에 수정하는 방법은 무엇입니까?

enter image description here

여기 내 코드의 흐림

에 후 다시 보여줍니다, 나는이 문제를 해결하는 방법을 모르겠어요. 내 기능 return false 전에 check_email 기능에서 잘

<!DOCTYPE HTML> 
    <html lang="en"> 
    <head> 
     <meta charset="utf-8"> 
     <title>Amateur</title> 
     <link rel="stylesheet" href="css/reset.css" type="text/css"> 
     <script src="http://code.jquery.com/jquery-1.8.0.js"></script> 
     <script> 
      function check_email() { 
       var email=$("#txtEmail").val(); 
       $.ajax(
       { 
        type:"POST", 
        url:"index.php", 
        data: "email="+email, 
        success:function(msg) { 
         $("#chkEmail").html(msg); 
        } 
       }); 
       return false; 
      } 
     </script> 
    </head> 

    <body> 
    <form method="post"> 
     <label for="txtEmail">E-mail:</label> 
      <input id="txtEmail" name="email" type="email" onblur="return check_email()"> 
     <label id="chkEmail" for="txtEmail"></label> 
     <?php 
     if(isset($_POST['email'])) 
     { 
      $user='root'; 

      $pdo=new PDO('mysql:host=localhost;dbname=class;charset=utf8',$user); 

      $email=$_POST['email']; 

      $stmt=$pdo->prepare('SELECT user_email from tbl_users WHERE user_email=:email LIMIT 1'); 
      $stmt->execute(array(':email'=>$email)); 

      if($stmt->rowCount()>0) { 
       echo 'E-mail already use.'; 
      } 
      else { 
       echo 'E-mail not use.'; 
      } 
     } 
     ?> 
    </form> 
    </body> 
    </html> 
+1

HTML, js, php를 모두 하나의 파일에 포함합니다. 거주지를 모르는 후에이 코드를 지원할 사람을 확인하십시오. – zerkms

+0

+ SQL 추가 포인트 –

+0

LOL, 무슨 문제입니까? : - –

답변

1

이렇게 코드를 변경하십시오. 문제는 POST와 동일한 페이지로 데이터를 보내고 전체 코드를 AJAX 요청에 대한 응답으로 얻는 것입니다. 따라서 POST에서 실행을 종료하면 관련 메시지 만 표시됩니다.

<?php 
     if(isset($_POST['email'])) 
     { 
      $user='root'; 

      $pdo=new PDO('mysql:host=localhost;dbname=class;charset=utf8',$user); 

      $email=$_POST['email']; 

      $stmt=$pdo->prepare('SELECT user_email from tbl_users WHERE user_email=:email LIMIT 1'); 
      $stmt->execute(array(':email'=>$email)); 

      if($stmt->rowCount()>0) { 
       echo 'E-mail already use.'; 
      } 
      else { 
       echo 'E-mail not use.'; 
      } 
      exit; 
     } 
     ?><!DOCTYPE HTML> 
    <html lang="en"> 
    <head> 
     <meta charset="utf-8"> 
     <title>Amateur</title> 
     <link rel="stylesheet" href="css/reset.css" type="text/css"> 
     <script src="http://code.jquery.com/jquery-1.8.0.js"></script> 
     <script> 
      function check_email() { 
       var email=$("#txtEmail").val(); 
       $.ajax(
       { 
        type:"POST", 
        url:"index.php", 
        data: { 
      'email': email 
       }, 
        success:function(msg) { 
         $("#chkEmail").html(msg); 
        } 
       }); 
       return false; 
      } 
     </script> 
    </head> 

    <body> 
    <form method="post"> 
     <label for="txtEmail">E-mail:</label> 
      <input id="txtEmail" name="email" type="email" onblur="return check_email()"> 
     <label id="chkEmail" for="txtEmail"></label> 

    </form> 
    </body> 
    </html> 
+0

주어진 소스 코드의 파일 이름은 무엇입니까? index.php입니까? –

+0

기다려주세요. 귀하의 POST –

+0

예, index.php에 문제가 있습니다. 내가 정말 HTML 밖에서 PHP 스크립트를 넣어해야합니까? –

-1

작동하지만

$("#txtEmail").hide(); 

이 당신이 무엇을 의미하는지가 추가?

+0

선생님, 출력은 한 줄만 입력하면 [email protected]으로 오류가 표시됩니다. –

+0

이 꾸미기 편집 –