|
|
|
อยากได้โค้ดตรวจสอบการรับค่า Textbox ให้รับค่าเฉพาะตัวเลข (web form) |
|
|
|
|
|
|
|
ใช้ jQuery ครับ
Code (JavaScript)
<script>
function inputNumberFunction(ctrl) {
$(ctrl).keydown(function (event) {
// Allow: delete, tab, enter and . - , f5
if ($.inArray(event.keyCode, [8, 9, 27, 13, 46, 109, 110, 190, 189, 116]) !== -1 ||
// Allow: Ctrl+A
(event.keyCode == 65 && event.ctrlKey === true) ||
// Allow: home, end, left, right
(event.keyCode >= 35 && event.keyCode <= 39)) {
// let it happen, don't do anything
return;
}
else {
// Ensure that it is a number and stop the keypress
if (event.shiftKey || (event.keyCode < 48 || event.keyCode > 57) && (event.keyCode < 96 || event.keyCode > 105)) {
event.preventDefault();
}
}
});
}
</script>
inputNumberFunction("#<%= txtInput.ClientID %>");
|
|
|
|
|
Date :
2015-10-16 10:56:41 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|