html之checkbox------checkbox只是input框的type属性

时间:2022-04-06 19:37:34
<html>
<body>


我喜欢自行车:<input type="checkbox" id="Bike">
<br />
我喜欢汽车:<input type="checkbox" id="Car">
<br />
<button onClick="output()">test</button>

<script>
function output()
{
if(document.getElementById("Bike").checked)
{
alert("1");
}

if(document.getElementById("Car").checked)
{
alert("2");
}
}
</script>
</body>
</html>

        是否选中, 直接看selected这个属性。

        另外注意, 在html中, checkbox并不是一个单独的标签, 而是input框的type属性, 这和我之前玩过的BCB/VC++不一致。