พูดคุยแลกเปลี่ยน ปัญหา การเขียน JavaScript เครื่องมือ AJAX Web 2.0 AJAX Framework jQuery และ Node.JS รวมถึง Framework Express ของ Node.JS ทำงานฝั่ง Server
Moderator: mindphp
eange08
PHP VIP Members
โพสต์: 10212 ลงทะเบียนเมื่อ: 22/12/2020 10:09 am
โพสต์
โดย eange08 » 16/03/2023 10:24 am
ทำช่องใส่วันที่หมดอายุแบบ mm/yyyy อยากให้เวลาคีย์ mm แล้วขึ้น / ให้เลยจะต้องเขียนอย่างไรค่ะ
ถามใน openai ยัง งงกับการเอามาแปลงใช้งานอยู่ค่ะ
โค้ด: เลือกทั้งหมด
$(document).ready(function() {
var maxLength = 100; // Set the maximum length of the input field
$('#text-input').on('input', function() {
var length = $(this).val().length; // Get the length of the user input
var remaining = maxLength - length; // Calculate the remaining characters
$('#char-count').text(remaining); // Update the character count display
});
});
ช่องวันหมดอายุ
โค้ด: เลือกทั้งหมด
<input name='package_noti_age' id='package_noti_age' type='text' class='input-short' maxlength='7'>
อยากให้ใส่รูปแบบนี้นะคะ
Selection_999(1110).png (5.54 KiB) Viewed 224 times
tsukasaz
PHP VIP Members
โพสต์: 19052 ลงทะเบียนเมื่อ: 18/04/2012 9:39 am
โพสต์
โดย tsukasaz » 16/03/2023 10:41 am
ลองดู code นี้นะครับ
HTML
โค้ด: เลือกทั้งหมด
<label for="date-input">Enter date (dd/yyyy): </label>
<input type="text" id="date_input" pattern="\d{2}/\d{4}" placeholder="dd/yyyy" maxlength="7">
JS โค้ด: เลือกทั้งหมด
$(document).ready(function(){
$('#date_input').keyup(function() {
const inputValue = $(this).val().replace(/\D/g, "");
const formattedValue = inputValue.replace(/(\d{2})(\d{4})/, "$1/$2");
$(this).val(formattedValue);
});
});
The last bug isn't fixed until the last user is dead. (Sidney Markowitz, 1995 )
eange08
PHP VIP Members
โพสต์: 10212 ลงทะเบียนเมื่อ: 22/12/2020 10:09 am
โพสต์
โดย eange08 » 16/03/2023 10:53 am
ใช้ได้แล้วค่ะ
สมาชิกกำลังดูบอร์ดนี้: Google [Bot] และบุคลทั่วไป 3