Loading...
การใช้ jquery-flexdatalist กับ ม (มอ ม้า)
ผู้เขียน : กฤษฎาพงษ์ สุตะ
เผยแพร่เมื่อ : 6 พฤศจิกายน 2565 11:59:11 ปรับปรุงเมื่อ : 6 พฤศจิกายน 2565 14:16:32
ลิงก์ : https://www.ef101.xyz/บทความ/การใช้-jquery-flexdatalist-กับ-ม-มอ-ม้า
เผยแพร่เมื่อ : 6 พฤศจิกายน 2565 11:59:11 ปรับปรุงเมื่อ : 6 พฤศจิกายน 2565 14:16:32
ลิงก์ : https://www.ef101.xyz/บทความ/การใช้-jquery-flexdatalist-กับ-ม-มอ-ม้า
ล่าสุดได้นำ jquery-flexdatalist มาใช้ทำช่อง input สำหรับ ระบบ tag ใช้งานได้ดี และง่าย เมื่อกด Enter หรือ , (Comma) ก็จะตัดคำให้ แต่เมื่อกด ม (มอ ม้า) ก็จะตัดคำเหมือนกัน ไม่สามารถพิมพ์ ม ได้
เพราะใน code ดักจับ keydown ทั้ง comma และ มอม้า ได้ keycode 188 เหมือนกัน เพราะเป็น key เดี๋ยวกัน แต่เมื่อดักจับ keypress เมื่อกดปุ่ม comma จะได้ keycode เป็น 44 และ ม ได้ keycode เป็น 3617 ผมเลยต้องมาแก้โค๊ดเอง และบันทึกไว้ใช้ และ แบ่งบัน
ไฟล์ jquery.flexdatalist.js
ค้นหา
.on(‘input keydown’, function (event) {
จะเจอ
// Keydown
.on('input keydown', function (event) {
if (_this.keyNum(event) === 9) {
_this.results.remove();
}
_this.action.keypressValue(event, 188);
_this.action.backSpaceKeyRemove(event);
})
// Keyup
.on('input keyup', function (event) {
_this.action.keypressValue(event, 13);
_this.action.keypressSearch(event);
_this.action.copyValue(event);
_this.action.backSpaceKeyRemove(event);
_this.action.showAllResults(event);
_this.action.clearValue(event);
_this.action.removeResults(event);
_this.action.inputWidth(event);
})
แก้ไขเป็น
// Keydown
.on('input keydown', function (event) {
if (_this.keyNum(event) === 9) {
_this.results.remove();
}
/* _this.action.keypressValue(event, 188); */
_this.action.backSpaceKeyRemove(event);
})
//keypress
.on('input keypress', function (event) {
_this.action.keypressValue(event, 44);
})
// Keyup
.on('input keyup', function (event) {
_this.action.keypressValue(event, 13);
_this.action.keypressSearch(event);
_this.action.copyValue(event);
_this.action.backSpaceKeyRemove(event);
_this.action.showAllResults(event);
_this.action.clearValue(event);
_this.action.removeResults(event);
_this.action.inputWidth(event);
})
โดยคอมเม้นต์
_this.action.keypressValue(event, 188);
แล้วแทรก
//keypress
.on('input keypress', function (event) {
_this.action.keypressValue(event, 44);
})
เพียงเท่านี้ก็จะสามารถพิมพ์ ม (มอม้า) ได้แล้วครับ ส่วนการตัดแท็กยังสามารถใช้ , (Comma) และ Enter ได้เหมือนเดิม
ความคิดเห็น :
เข้าสู่ระบบก่อนจึงจะแสดงความคิดเห็นได้
ค้นหา
หมวดหมู่
5 บทความล่าสุด
แท็ก