为了账号安全,请及时绑定邮箱和手机立即绑定

var hobby = document.getElementById("hobby"+j);是什么意思?

任务

在文本框中输入输入1-6数值,当点击"确定"按钮时,根据输入的数值,通过id选中相应的复选项。

<!DOCTYPE HTML>

<html>

    <head>

        <meta http-equiv="Content-Type" content="text/html; charset=gb2312">

        <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 type="button" value = "全选" onclick = "checkall();">

          <input type="button" value = "全不选" onclick = "clearall();">

          <p>请输入您要选择爱好的序号,序号为1-6:</p>

          <input id="wb" name="wb" type="text" >

          <input name="ok" type="button" value="确定" onclick = "checkone();">

        </form>

          

<script type="text/javascript">

  function checkone(){
            var j=document.getElementById("wb").value;
            var hobby = document.getElementById("hobby"+j);
            hobby.checked = true;    }  

 </script>

    </body>

</html>

 var hobby = document.getElementById("hobby"+j);是什么意思?id+value值是什么意思?看不懂了,求大神指教!!

正在回答

3 回答

可是没有id=hobby这个节点呀!

2 回复 有任何疑惑可以回复我~
#1

慕数据5775487 提问者

基本弄明白了,意思是你在输入框输入几,那个ID就就是hobby几,比如输入数字2,那和那个ID号就是hobby2,说明document.getElementById("hobby")返回的是字符串hobby,加上document.getElementById("wb").value返回的是数字,那么 字符串+数字=字符串,所以document.getElementById("hobby"+j)返回的就是字符串hobbyj,如输入的数字为2,返回的ID号就是hobby2!明白了吗?
2016-11-22 回复 有任何疑惑可以回复我~
#2

bestMan 回复 慕数据5775487 提问者

66666
2017-12-01 回复 有任何疑惑可以回复我~

nice



0 回复 有任何疑惑可以回复我~

66666明白了  明白了。

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

var hobby = document.getElementById("hobby"+j);是什么意思?

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号