电脑上多选框的使用技巧与实例
一、多选框使用技巧
<fieldset>和<legend>元素将其分组,以便于用户理解和操作。二、多选框使用实例
以下是一个简单的HTML多选框使用实例:
|
|
<!DOCTYPE html> |
|
|
<html lang="zh-CN"> |
|
|
<head> |
|
|
<meta charset="UTF-8" /> |
|
|
<title>多选框使用实例</title> |
|
|
</head> |
|
|
<body> |
|
|
<form> |
|
|
<h2>请选择你喜欢的水果:</h2> |
|
|
<input type="checkbox" id="apple" name="fruit" value="apple"> |
|
|
<label for="apple">苹果</label> |
|
|
|
|
|
<input type="checkbox" id="banana" name="fruit" value="banana"> |
|
|
<label for="banana">香蕉</label> |
|
|
|
|
|
<input type="checkbox" id="orange" name="fruit" value="orange"> |
|
|
<label for="orange">橙子</label> |
|
|
|
|
|
<br /> |
|
|
|
|
|
<input type="button" value="全选" onclick="checkAll('fruit')"> |
|
|
<input type="button" value="全不选" onclick="cancelCheckAll('fruit')"> |
|
|
|
|
|
<script> |
|
|
function checkAll(name) { |
|
|
var checkboxes = document.getElementsByName(name); |
|
|
for (var i = 0; i < checkboxes.length; i++) { |
|
|
checkboxes[i].checked = true; |
|
|
} |
|
|
} |
|
|
|
|
|
function cancelCheckAll(name) { |
|
|
var checkboxes = document.getElementsByName(name); |
|
|
for (var i = 0; i < checkboxes.length; i++) { |
|
|
checkboxes[i].checked = false; |
|
|
} |
|
|
} |
|
|
</script> |
|
|
</form> |
|
|
</body> |
|
|
</html> |
在这个实例中,我们创建了一个包含三个多选框的表单,分别代表苹果、香蕉和橙子。同时,我们添加了两个按钮,用于实现全选和全不选的功能。当用户点击“全选”按钮时,所有多选框都会被选中;当用户点击“全不选”按钮时,所有多选框都会被取消选中。
版权归【铅笔录 - www.winyg.com】所有,严禁转载。
本文链接:https://www.winyg.com/10141.html