Web/Javascript
input 박스 enter 쳤을때, 처리하기 + 숫자만 입력 받기
saltdoll
2010. 12. 7. 00:03
반응형
<input>에 엔터키를 이벤트 처리를 위해
onkeypress="return enterKey(event);"
DHTML 이벤트를 추가한다.
해당 function에서 e.keyCode==13일때 함수 처리
출처: http://mystria.egloos.com/3998558
또다른 간단한 소스
onkeypress="return enterKey(event);"
DHTML 이벤트를 추가한다.
해당 function에서 e.keyCode==13일때 함수 처리
<script type="text/javascript">
function enterKey(e){
...
if(e.keyCode == 13){ /* IE기준으로 설명 */
...
return false;
}
else{
return true;
}
}
</script>
<input type="text" id="text1" onkeypress="return enterKey(event);" />
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
출처: http://mystria.egloos.com/3998558
또다른 간단한 소스
<script type="text/javascript">
function enterkey() {
if (event.keyCode == 13) {
</script>
function enterkey() {
if (event.keyCode == 13) {
alert('Enter 키 사용~~!!');
return false;
return false;
}
}
document.onkeypress=enterkey}
</script>
<input> 태그에 숫자만 입력하기
전화 번화 값 (949) 333-4444을 복붙하면, 9493334444로 입력이 됩니다.
<input type="text" class="form-control" id="new_map_phone" name="new_map_phone" placeholder="Phone #" maxlength="15" |
You can limit the input to only numbers using a regular expression:
//bind to the `keyup` event for all `input` element(s)
$('input').on('keyup', function () {
//replace the value of this input by only the digits in it's value
//note that this method works even if the user pastes a block of text into the input
this.value = this.value.replace(/[^0-9]/gi, '');
});
반응형