In jquery, you can use the attr() method to set the disabled attribute to make the text box uneditable. The disabled attribute can specify that the text area is disabled (not editable); the syntax is "$("textarea").attr ("disabled","disabled");".
The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.
In jquery, you can use the attr() method to set the disabled attribute to make the text box uneditable.
The disabled property is a Boolean property. The disabled attribute specifies that the text area should be disabled. A disabled text area is neither usable nor the text selectable (cannot be copied).
Just use the attr() method to set the disabled attribute to the textarea element of the text box.
Grammar:
$("textarea").attr("disabled","disabled"); $("textarea").attr("disabled","true");
Example:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <script src="js/jquery-1.10.2.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $("button").click(function() { $("textarea").attr("disabled", "disabled"); // $("textarea").attr("disabled","true"); }); }); </script> </head> <body> <textarea></textarea><br><br> <button>让textarea不可编辑</button> </body> </html>
jQuery video tutorial, Web front-end introductory tutorial】
The above is the detailed content of How to make the text box uneditable in jquery. For more information, please follow other related articles on the PHP Chinese website!