JQuery if checkbox is checked Bootstrap switch

To show the value of the checkbox by JQuery


JQuery if checkbox is checked Bootstrap switch

1. กำหนดค่า

$('#txtBox').bootstrapSwitch('state', true  );
2. เวลาตอนทำการคลิกเพื่อให้ switch on/off
$('#txtBox').on('switchChange.bootstrapSwitch', function (event, state) {
     console.log(state);
});

3. แสดงค่าใน CheckBox
console.log('check txtBox is : ' + $('#txtBox').is(':checked') + ' '+ $('#txtBox').prop('checked'));
หมายเหตุ สำหรับ ตัวอย่างการใช้งาน bootstrap-switch ตามลิงด้านล่างเลยครับ https://github.com/Bttstrp/bootstrap-switch
Boonyadol Morruchai (Senior Full-stack Developer)

ผมเป็น IT Professional ที่มีประสบการณ์ในสายงานมากว่า 20 ปี เชี่ยวชาญการออกแบบระบบ Enterprise และ Automation Tools ปัจจุบันมุ่งเน้นการประยุกต์ใช้ AI (Gemini/OpenAI) เพื่อเพิ่มประสิทธิภาพในการเขียน Code และการจัดการข้อมูลขนาดใหญ่ บล็อกนี้สร้างขึ้นเพื่อแชร์ "ประสบการณ์หน้างาน" ปัญหาจริงที่เจอ และวิธีแก้ปัญหาฉบับ Senior Dev ครับ

แสดงความคิดเห็น

ใหม่กว่า เก่ากว่า