无线电价值检索

时间:2013-08-28 22:07:46

标签: javascript html html5

我不相信有一个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>

1 个答案:

答案 0 :(得分:3)

attribute selector传递给document.querySelector应该可以解决问题:

var radioButton = document.querySelector('input[value="Yes"]');