html中怎么在单元格里做复选框?

html中怎么在单元格里做复选框?,第1张

使用checkbox属性,代码如下

<html>

<body>

<table border="1">

<tr>

<th><input type="checkbox" onclick="swapCheck()" /></th>

<th>Month</th>

<th>Savings</th>

</tr>

<tr>

<td><input type="checkbox" /></td>

<td>January</td>

<td>$100</td>

</tr>

<tr>

<td><input type="checkbox" /></td>

<td>February</td>

<td>$150</td>

</tr>

</table>

</body>

</html>

多选一应该使用单选框呀,把你的<form>...</form>部分贴上来看看。

补充:

那你的意思是说,这个<form>里面的checkbox,至少要选中一个,否则就算空,因为不能要求所有都必须选择,是?

那样我认为,可以用循环检测所有的checkbox,如果有一个选中就设置变量has1为true,我写了下面的例子代码:

<form name='form1'>

<input type='checkbox' name='VoteOption1' value=1>通过本课程学习了解<br>

<input type='checkbox' name='VoteOption1' value=2>掌握具体的网络方法<br>

<input type='checkbox' name='VoteOption1' value=3>掌握一些基本原理与方法

</form>

<script type=text/javascript>

has1=false

for (i=0i<document.form1.lengthi++)

if (document.form1.elements[i].type=='checkbox')

if (document.form1.elements[i].checked) has1=true

if (has1==false) alert('一个都没有选')

</script>


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/bake/11797296.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-18
下一篇 2023-05-18

发表评论

登录后才能评论

评论列表(0条)

保存