我正在尝试限制文本框中的特殊字符。我限制了 字符。但不是特殊的角色。我已粘贴代码 我正在尝试。
<input type="text" name="" class="zip zipCode">
var $currentZip;
// Override WM enter key event
$(".zipCode").keydown(function(event) {
if (event.keyCode == 13) {
event.preventDefault()
$currentZip = $(this)
zipUrl($currentZip)
}
if (event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 13) {
// Let it happen, don't do anything
} else {
// Make sure that it is a number and stop the keypress
if (event.keyCode < 48 || event.keyCode > 57 && event.keyCode < 96 || event.keyCode > 105) {
console.log("Keycode :"+ event.keyCode)
event.preventDefault();
}
}
}).keyup(function() {
var $this = $(this);
if ($this.val().length > 5)
$this.val($this.val().substr(0, 5))
});
$('.zipSubmit').on('click', function() {
$currentZip = $(this).closest('.wrapper').find('.zipCode')
console.log($currentZip.attr('type'))
zipUrl($currentZip);
});