[英]How to allow only numbers in select2 dropdown search box in jquery?
I am using select2 drop-down in jQuery, i have to allow only numbers and not allow space and characters in search box.. Please help me 我在jQuery中使用select2下拉列表,我只允许数字而不允许空格和字符在搜索框中。
my code is: 我的代码是:
<script>
$(document).ready(function () {
//The url we will send our get request to
var attendeeUrl = '@Url.Action("GetAttendees", "Home")';
var pageSize = 20;
$('#attendee').select2(
{
placeholder: 'Enter name',
//Does the user have to enter any data before sending the ajax request
minimumInputLength: 0,
allowClear: true,
multiselect:true,
ajax: {
//How long the user has to pause their typing before sending the next request
quietMillis: 150,
//The url of the json service
url: attendeeUrl,
dataType: 'jsonp',
//Our search term and what page we are on
data: function (term, page) {
debugger;
return {
pageSize: pageSize,
pageNum: page,
searchTerm: term
};
},
results: function (data, page) {
//Used to determine whether or not there are more results available,
//and if requests for more data should be sent in the infinite scrolling
var more = (page * pageSize) < data.Total;
return { results: data.Results, more: more };
}
}
});
});
</script>
Try Something Like 尝试类似的东西
$(document).ready(function () {
//called when key is pressed in textbox
$("#quantity").keypress(function (e) {
//if the letter is not digit then display error and don't type anything
if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
//display error message
$("#errmsg").html("Digits Only").show().fadeOut("slow");
return false;
}
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.