How To Disable All Input Controls Inside A Form Using JQuery
Có thể bạn quan tâm
Topic: JavaScript / jQueryPrev|Next
Answer: Use the jQuery prop() method
You can use the jQuery prop() method in combination with the :input selector to disable all <input>, <textarea>, <select> and <button> elements inside an HTML form dynamically using jQuery. The prop() method require jQuery 1.6 and above.
Let's check out an example to understand how this method basically works:
Example
Try this code » <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>jQuery Disable All Form Elements</title> <style> label { display: block; margin-bottom: 5px; } label, input, textarea, select { margin-bottom: 10px; } </style> <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> <script> $(document).ready(function(){ $("#myForm :input").prop("disabled", true); }); </script> </head> <body> <form id="myForm"> <label>Name:</label> <input type="text"> <label>Address:</label> <textarea></textarea> <label>Country:</label> <select> <option>select</option> </select> <br> <button type="button">Submit</button> <button type="button">Reset</button> </form> </body> </html>Related FAQ
Here are some more FAQ related to this topic:
- How to add attribute to an HTML element in jQuery
- How to disable or enable a form element using jQuery
- How to remove the clickable behavior from a disabled link using jQuery
Advertisements Is this website helpful to you? Please give us a like, or share your feedback to help us improve. Connect with us on Facebook and Twitter for the latest updates.
About Us
Our Story Terms of Use Privacy PolicyContact
Contact Us Report Error AdvertiseInteractive Tools
Bootstrap Icon Search Utility HTML Formatter Title & Meta Length Calculator HTML Color Picker Bootstrap Button Generator SQL Playground Font Awesome Icon Finder HTML Editor
Copyright © 2025 Tutorial Republic. All Rights Reserved. Share This:
Từ khóa » Html Form Block Input
-
HTML Input Disabled Attribute - W3Schools
-
HTML Input Readonly Attribute - W3Schools
-
How To Disable An Input Type=text? - Javascript - Stack Overflow
-
HTML Attribute: Disabled - HTML: HyperText Markup Language | MDN
-
: The Input (Form Input) Element - HTML - MDN Web Docs
-
Which Attribute Is Used To Disabled The Specific Input Field In HTML ...
-
JavaScript - Input Field Enable And Disable - C# Corner
-
Disable HTML Form Input Autocomplete And Autofill - GitHub Gist
-
HTML And CSS Tutorial: The Intermediates
-
Disable Input Html Form Code Example - Code Grepper
-
How To Block Input Text In Html Code Example
-
Forms - Bootstrap
-
How To Disable A Form Field To Prevent User Input - WPForms
-
How To Disable The Browser Autocomplete And Autofill On HTML ...