用户帮助我在页面中找到隐藏的值并使用alert显示它。如果有单选按钮,其中一个与此值相关,有没有办法自动选择单选按钮而不是在警告框中显示值..谢谢......
代码如下:
var inputs = document.getElementsByTagName('input');
for (i=0; i<inputs.length; i++) {
if (inputs[i].getAttribute("name") == "ans") {
alert(inputs[i].getAttribute("value"));
}
}
必须在单选按钮中选择此“值”而不是警告......
html代码在这里:
因此我需要在页面加载后检查具有“人类行为的基础统一”值的选项..谢谢
<table style="margin-left:20px" align="center" width="450" border=0> <form name="bloogs" action="/mywebsite.php" id="bloogs" method="post" > <tr><td align="left" class="formHeading" colspan=2 ><b><font size="4px"> world</font></b></td> <td class="log" align="right" width=150 ><a href="website.php">Back to <br>Regular Index</a></td> </tr> <tr> <td colspan=3 align="right" valign="top" height="30px"><div id="Time" style=""></td> </tr> <input type="hidden" name="ans" value="Underlying Unity of Human Behaviours" /> <input type="hidden" name="pno" value="3" /> <input type="hidden" name="quesid" value="3005" /> <tr> <td valign="top" width=20><b>3. </b> </td> <td class="ques" colspan=2>Which is the basic assumption of case study?</td> </tr> <tr> <td></td> <td height="10" class="Textbold" colspan=2></td> </tr> <tr><td></td> <td class="" colspan=2><div class="ans" id="opt1" style="" ><input type="radio" id="r1" name="opt" value="Data"> Data</div></td> </tr> <tr><td></td> <td class="" colspan=2><div class="ans" id="opt2" style="" ><input type="radio" id="r2" name="opt" value="Necessity"> Necessity</div></td> </tr> <tr><td></td> <td class="" colspan=2><div class="ans" id="opt3" style="" ><input type="radio" id="r3" name="opt" value="Observation"> Observation</div></a></td> </tr> <tr><td></td> <td class="" colspan=2><div class="ans" id="opt4" style="" ><input type="radio" id="r4" name="opt" value="Underlying Unity of Human Behaviours"> Underlying Unity of Human Behaviours</div></td> </tr> <tr><td></td> <td height="20"> </td> </td> </tr> <tr height=50><td align='right' width=350 colspan=3><input class='button' id='checkans' value='Attempt' type='submit' name='checkans'/> <input class='button' id='' value='Skip' type='submit' name='skip'/></td></tr></form> </td> </tr> </table>
答案 0 :(得分:1)
您是否只想查看单选按钮?
var inputs = document.getElementsByTagName('input');
for (i=0; i<inputs.length; i++) {
if (inputs[i].getAttribute("name") == "ans") {
inputs[i].checked = true;
}
}
see here:D