How to make select unavailable in jquery: 1. Use the attr method to disable it, the code is [$("#select").attr("disabled","disabled")]; 2. jquery makes select Unavailable, the code is [
The operating environment of this tutorial: windows7 system, jquery3.2.1 version, DELL G3 computer, This method is suitable for all brands of computers.
Recommendation: jquery tutorial
jquery method to make select unavailable:
Generally use the
attr
method to disable$("#select").attr("disabled","disabled");Copy after loginCancel the disabling
Mainly use the
removeAttr
method to remove the disabled attribute to cancel the disabling$("#select").removeAttr("disabled");Copy after loginExample: jquery makes select unavailable
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Title</title> <style> select{ /*为了看到效果这里添加了宽和高*/ width:100%; height:100px; margin:100px 0; } </style> <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script> </head> <body> <div id="div1"> <select id="select1"> <option value="1">我是第一个option</option> <option value="2">我是第二个option</option> <option value="3">我是第三个option</option> <option value="4">我是第四个option</option> </select> </div> <div id="select2"> <select> <option value="1">我是第一个option</option> <option value="2">我是第二个option</option> <option value="3">我是第三个option</option> <option value="4">我是第四个option</option> </select> </div> <script> $(function(){ $("select").each(function () { $(this).attr("disabled","disabled"); }); }); </script> </body> </html>Copy after loginFor more programming-related knowledge, please visit: Programming Teaching!!
The above is the detailed content of How to make select unavailable in jquery. For more information, please follow other related articles on the PHP Chinese website!