我不相信有一个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>
答案 0 :(得分:3)
将attribute selector传递给document.querySelector
应该可以解决问题:
var radioButton = document.querySelector('input[value="Yes"]');