Home > Article > Web Front-end > How to make the id element uneditable in jquery
Jquery method to make the id element uneditable: 1. Get the specified element through the id attribute value, the syntax "$("#id value")" will return a jquery object containing the specified element; 2. Use Attr() sets the disabled attribute to the obtained element object to make the element uneditable. The syntax is "id element object.attr("disabled", "disabled");".
The operating environment of this tutorial: windows7 system, jquery3.6.0 version, Dell G3 computer.
jquery method to make the id element uneditable
1. Get the specified element through the id attribute value
$("#id值")
will return a jquery object containing the specified element
2. Make the obtained element object uneditable
Just use the attr() method to add the element Set the disabled attribute to make the element uneditable.
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <script src="./js/jquery-3.6.0.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $("#box").css("border","1px solid red"); $("button").click(function() { $("#box").attr("disabled", "disabled"); // $("textarea").attr("disabled","true"); }); }); </script> </head> <body> <textarea></textarea><br><br> <textarea id="box">id="box"元素</textarea><br><br> <button>让id="box"元素不可编辑</button> </body> </html>
[Recommended learning: jQuery video tutorial, web front-end video】
The above is the detailed content of How to make the id element uneditable in jquery. For more information, please follow other related articles on the PHP Chinese website!