2013-05-24 11 views
-5

암호 입력란에 자리 표시자를 사용했습니다. 암호 입력 필드의 입력 유형이 "텍스트"이면 암호를 입력해도 제대로 작동하지 않습니다.암호 입력란에 자리 표시자가 작동하지 않습니다.

암호를 입력하면 암호의 첫 번째 문자가 올바르게 입력되지 않습니다. 키 누르기가 처음 작동하지 않습니다.

은 아래 링크를 그것이 내가 자리의 암호 필드를 사용하고 팝업 창을 열고 로그인 버튼을

http://www.techmodi.com/demo/firstjitters/

클릭을 클릭하십시오.

코드 :

<input name="password" id="password" type="text" class="input" tabindex="2" placeholder="Password" /> 

JS 파일 :

window.onload = function() { 
    var arrInputs = document.getElementsByTagName("input"); 
    for (var i = 0; i < arrInputs.length; i++) { 
     var curInput = arrInputs[i]; 
     if (!curInput.type || curInput.type == "" || curInput.type == "text" || curInput.type == "password") 
      HandlePlaceholder(curInput); 
    } 
}; 

function HandlePlaceholder(oTextbox) { 
    //alert(typeof oTextbox.placeholder); 
    if (typeof oTextbox.placeholder == 'string') { 
     var curPlaceholder = oTextbox.getAttribute("placeholder"); 
     if (curPlaceholder && curPlaceholder.length > 0) { 
      oTextbox.value = curPlaceholder; 
      oTextbox.setAttribute("old_color", oTextbox.style.color); 
      oTextbox.style.color = "#c0c0c0"; 
      oTextbox.onfocus = function() { 
       this.style.color = this.getAttribute("old_color"); 
       if (this.value === curPlaceholder) 
        this.value = ""; 
      }; 
      oTextbox.onblur = function() { 
       if (this.value === "") { 
        this.style.color = "#c0c0c0"; 
        this.value = curPlaceholder; 
       } 
      }; 
     } 
    } 
} 
+2

질문에 코드를 추가 할 수 있습니까? – andrewsi

+0

IE에서 질문에 태그를 추가했는데이 문제는 IE에서만 발생합니까? 그렇다면 어떤 버전입니까? – j08691

+0

아니요 ...이 문제는 mozilla (버전 : 21.0)에서도 발생합니다. IE-8 및 크롬과 동일 – user2417911

답변

1

당신이 게시 한 코드가 placeholder 속성을 지원하고 함께 할 수 없다하지 않는 오래된 브라우저에 대한 주변의 일입니다 너의 문제.

귀하의 문제는 어느를 해결해야하는 대신 onfocus에 트리거를 변경하려면 텍스트 필드로 시작하고 사용자가 내가 onkeyup 또는 onchange 같은 것을 사용하여 추측하고있어 그 안에 입력 시작할 때 암호 필드에이를 변환하는 것이 당신의 문제.

+0

위의 코드에서 솔루션을 제공하십시오 ... – user2417911

+1

저는 올바른 방향으로 여러분을 지적했습니다. 여러분의 코드를 살펴보고 이것이 어디에서 일어나고 있는지 확인합니다. 물론 아닙니다. – RMcLeod

+0

죄송합니다. 보스 ... 방금 물어 봤는데 ... 나는 더 신선하고 구글 에서이 스크립트를 검색하고 내 코드에서 사용 ... – user2417911

관련 문제