如何在 jQuery 中設定複選框不可選中?


若要設定複選框不可選中,請將 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 編輯器中選擇 “Use Live Server 開啟” 選項。

輸出

輸出如下所示 −

無法選中上述複選框,因為我們已將其停用。

更新於:2020 年 10 月 3 日

217 次瀏覽

開啟你的職業生涯

透過完成課程獲得認證

開始學習
廣告
© . All rights reserved.