문자 나 숫자가 아닌 HTML 텍스트 입력 필드에 문자를 입력하지 못하게하고 싶습니다.jQuery의 이벤트 개체에서 키 누르기 값을 얻는 방법
이 정확한 기능은 Twitter 등록 페이지 (사용자 이름 필드) https://twitter.com/signup에서 볼 수 있습니다.
나는 이것을 jQuery에 쓰려고합니다. 그러나 나는 어떤 키를 눌렀는지와 그 값이 받아 들여질 수 있는지를 테스트하기 위해 입력 키 누르기 이벤트 값을 가져올 수 있어야합니다.
<input type="text" id="username" name="username" />
<script type="text/javascript">
$("#username").keypress(function(event){
// Get the keypress value
// ...?
// If the keypress value is illegal then disable it
if (...){
event.preventDefault();
}
});
</script>
수정 링크를 시도하십시오 http://api.jquery.com/keypress/를 또한 http://api.jquery.com/event 참조 .which/event.which에 관한 더 많은 정보를 위해 –
whewww 멋진 남자 :) – Nav