|
|
|
ช่วยดู Script นี้ให้ด้วยครับ อยากให้คีย์ได้เฉพาะตัวเลขและจุดทศนิยม เท่านั้น |
|
|
|
|
|
|
|
ลองหาๆพวกใช้ Jquery ดูผมว่าก็สะดวกดีนะครับ
|
|
|
|
|
Date :
2016-07-13 16:16:35 |
By :
ผ่านมาแล้วก็ผ่านไป |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#num").on("keypress keyup blur",function (event) {
$(this).val($(this).val().replace(/[^0-9\.]/g,''));
if ((event.which != 46 || $(this).val().indexOf('.') != -1) && (event.which < 48 || event.which > 57)) {
event.preventDefault();
}
});
});
</script>
<input type="text" id="num">
</body>
</html>
|
ประวัติการแก้ไข 2016-07-13 16:56:58
|
|
|
|
Date :
2016-07-13 16:56:15 |
By :
dudesaranyu |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<input type="text" class="number" name="text1">
<script>
$(document).ready(function() {
$(".number").keydown(function (e) {
// Allow: backspace, delete, tab, escape, enter and .
if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110, 190]) !== -1 ||
// Allow: Ctrl+A, Command+A
(e.keyCode == 65 && ( e.ctrlKey === true || e.metaKey === true ) ) ||
// Allow: home, end, left, right, down, up
(e.keyCode >= 35 && e.keyCode <= 40)) {
// let it happen, don't do anything
return;
}
// Ensure that it is a number and stop the keypress
if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
e.preventDefault();
}
});
});
</script>
|
|
|
|
|
Date :
2016-07-14 10:22:02 |
By :
compiak |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|