Devdit
 

วิธี jQuery attr disabled

884

วิธี jQuery attr disabled บทความนี้สอนใช้ jQuery Framework สำหรับการสั่ง disabled หรือระงับการใช้งานของ input ที่ต้องการ ผ่านคำสั่ง attr จากตัวอย่างเป็นการ disabled input type text สามารถเขียนโปรแกรมได้ดังนี้

 

ตัวอย่าง วิธี jQuery attr disabled

<input type="text" id="txt">
<input type="button" value="Disabled" id="btn">
<script>
    $("#btn").click(function(){
        $("#txt").attr("disabled", true);
    });
</script>

คำอธิบาย

จากตัวอย่างสร้าง input type text กำหนด id="txt" และปุ่ม input type button กำหนด id="btn" เมื่อผู้ใช้งานกดปุ่มจะทำงานใน $("#btn").click จากนั้นเข้าถึง id="txt" และกำหนด disabled เท่ากับ true ด้วยคำสั่ง attr ของ jQuery Framework

เขียน 1 ปีที่แล้ว
ชอบ
ลิ้งก์
แชร์
Devdit มีช่อง YouTube แล้ว
เราสร้างวิดีโอเกี่ยวกับเทคโนโลยี ทำตามง่ายๆ