0

我不相信有 getElementByValue() 方法,但有没有办法在我的表单中检索“是”值?

<form>
    Do you work at Mori Seiki? <br />
    <input type ="radio" name = "group1_answers" value = "Yes" /> Yes <br />
    <input type ="radio" name = "group1_answers" value = "No" /> No <br />
    <input type ="radio" name = "group1_answers" value = "Perhaps" /> Perhaps <br /> 

    Your answer is: <input type ="text" id = "work_answer" />
    <script>
        if(document.getElementByValue('Yes')){   <-- similar function?
            ;
        }
    </script>
</form>
4

1 回答 1

3

将属性选择器传递给document.querySelector应该可以解决问题:

var radioButton = document.querySelector('input[value="Yes"]');
于 2013-08-28T22:08:38.137 回答