2012-06-26 8 views
4

SSN, 전화 번호 및 이메일 ID와 같은 텍스트 필드가 거의 없습니다. onfocus와 같은 작업을하고 싶습니다. 입력 상자의 전체 내용을 표시하고 흐리게 처리하면 내용을 다시 마스킹해야합니다 (예 : asterix). 미리 감사드립니다. 미리 감사드립니다.html로 입력 텍스트 마스크 및 마스크 해제

답변

10

두 이벤트에서 <input> 요소의 유형을 passwordtext 사이에서 전환 할 수 있습니다. 이 내용은 example fiddle을 참조하십시오.

HTML

<input type="password" id="target" /> 

JS

<script> 
var inp = document.querySelector('#target'); 

inp.addEventListener('focus', function(){ 
    inp.type = 'text'; 
}); 
inp.addEventListener('blur', function(){ 
    inp.type = 'password'; 
}); 
</script> 
+0

또는 우리 :

<input type="text" id="emailId" name="emailId" /> 

을 다음, 할 e jQuery $ ('# target'). focus (function() {$ (this) .attr ('type', 'text')}); – Onheiron

+0

@Onheiron가 작동하지 않습니다. http://stackoverflow.com/questions/8378563/why-cant-i-change-the-type-of-an-input-element-to-submit – Technomad

+0

위의 바이올린은 Mootools 라이브러리를 포함합니다. 업데이트 된 [fiddle] (http://jsfiddle.net/VWAhC/87)은 Mootools 라이브러리가없는 동일한 코드와 입력 상자 주변의 테두리가 보이기 때문에 보았습니다. –

0

<input type="password" /> 간단 해.

1

같이 그것을 시도 :

var emailIdValue = ""; 

$(document).ready(function() { 

    emailIdValue = $('#emailId').val(); 

    $('#emailId').val("********"); 

    $('#emailId').focus(function() { 

      $(this).val(emailIdValue); 

    }).focusout(function() { 

      emailIdValue = $(this).val(); 
      $(this).val('********'); 

    }); 

});