问答详情
源自:9-4 区别getElementByID,getElementsByName,getElementsByTagName

为什么我这样不行

function checkone(){

            var j=document.getElementById("wb").value;

        var hobby = document.getElementByName("hobby");

        hobby[j-1].checked=true;

         // 任务3

        

        }


提问者:用户1173044 2015-01-20 16:54

个回答

  • 凉宫落寒
    2015-01-20 17:02:28
    已采纳

    var hobby = document.getElementsByName("hobby");//注意S


  • 小慧__Bui
    2015-03-28 16:00:46

    Are you sure this works? Because I tried this too but it fails. Here's my code:

    function checkone(){

                var j=document.getElementById("wb").value;

            var hobby = document.getElementByName("hobby");

            hobby[parseInt(j)-1].checked=true;}

    (I'm sorry I have to type English because the computer I'm using isn't installed with a Chinese input method~~)


  • L_J
    2015-01-20 17:03:39

    是不是这个写错了?document.getElementsByTagName("hobby");