如何在 jQuery 中使复选框无法选中?

jqueryweb developmentfront end technology

要使复选框无法选中,请将 disabled 属性设置为 true。

<input type="checkbox" value="JavaScript" disabled=true>JavaScript

以下是代码 −

示例

以下是代码 −

<!DOCTYPE html>
<html lang="en">
<head>
   <meta charset="UTF-8">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <title>Document</title>
</head>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<body>
   <label>List Of Subject names</label>
   <input type="checkbox" value="MySQL" disabled=true>MySQL
   <input type="checkbox" value="JavaScript" disabled=true>JavaScript
   <input type="checkbox" value="MongoDB" disabled=true>MongoDB
</body>
<script>
</script>
</html>

要运行上述程序,请将文件另存为 anyName.html(或 index.html)。右键单击该文件,然后在 VS Code 编辑器中选择"使用 Live Server 打开"选项。

输出

输出如下 −

由于我们已禁用上述复选框,因此您无法选中该复选框。


相关文章