2016-06-20 5 views
0

입력 필드에 숫자 값만 연결하거나 더하기/빼기 버튼을 클릭하여 값을 선택할 수있는 더하기/빼기 버튼이 있습니다. 텍스트 입력란을 클릭하여 삭제하거나 번호를 다시 입력하면 작동하지 않습니다. 여기 HTML과 내 피들 링크가 있습니다. 업데이트 : 삭제 키는 Chrome에서는 작동하지만 Firefox에서는 작동하지 않습니다. https://jsfiddle.net/714dxayk/5/입력 필드의 텍스트 삭제가 작동하지 않습니다.

<span class="form-title">Quantity</span> 
<form id='myform' method='POST' action='#' class="numbo"> 
<input type='button' value='-' class='qtyminus' field='quantity' style="font-weight: bold; font-size:18px;" /> 
<input type='text' name='quantity' value='1' class='qty' style="margin-bottom: 0px !important" onkeypress='return event.charCode >= 48 && event.charCode <= 57'/> 
<input type='button' value='+' class='qtyplus' field='quantity' style="font-weight: bold; font-size:18px;" /> 
</form> 
+0

나는 스크립트가없는 것을 어떻게 알 수 있습니까? –

+0

나는 그것을 고치려고하는 것이 아니기 때문에 나는 자바 스크립트를 넣지 않았다. – sizemattic

+0

그게 도움이된다면 javascript로 내 바이올린을 편집했습니다. – sizemattic

답변

0

입력 필드에 키 누르기 핸들러를 지정해보십시오. 핸들러에서 브라우저가 특정 키 누름을 처리하고 다른 키 누름을 무시하도록합니다.

$('.qty').keypress(function(ev){ 
    // Don't ignore numbers. 
    if (ev.charCode >= 48 && ev.charCode <= 57) { 
     return; 
    } 

    // Don't ignore BS, DEL, and arrow keys. 
    switch (ev.keyCode) { 
     case 8: // backspace 
     case 46: // delete key 
     case 37: // arrows 
     case 38: 
     case 39: 
     case 40: 
      return; 
    } 

    // Ignore the rest of the keys. 
    ev.preventDefault(); 
}); 
관련 문제