这个为什么只输出了一个hobby1呢?大佬们求看
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
</head>
<body>
<form>
请选择你爱好:<br>
<input type="checkbox" name="hobby" id="hobby1"> 音乐
<input type="checkbox" name="hobby" id="hobby2"> 登山
<input type="checkbox" name="hobby" id="hobby3"> 游泳
<input type="checkbox" name="hobby" id="hobby4"> 阅读
<input type="checkbox" name="hobby" id="hobby5"> 打球
<input type="checkbox" name="hobby" id="hobby6"> 跑步 <br>
<input name="get" type="button" value="获取hobby的id属性值" onclick = "getid();">
</form>
<script type="text/javascript">
function getid(){
var con=document.getElementsByName("hobby");
var i=0;
while(i<con.length){
var text=con[i].getAttribute("id");
document.write(text+"<br>");
i++;
}
}
</script>
</body>
</html>