javascript动态获取单选按钮信息
我用Foreach动态显示出了单选信息,现在我要在javascript中获取选中的值,怎么做啊?代码如下:
<c:forEach items="${collList}" var="coll">
<input name="collecta" type="radio" value="${coll.id }"
title="${coll.id }" />${coll.collecttitle }
<br>
</c:forEach>
<input name="Submit" type="button" value="提交">
<input name="Submit" type="button" value="查看">
------解决方案--------------------var all = document.getElementsByTagName( "input" );
for(var i=0;i<all.length;i++)
{
if(all[i].type=='radio'|| all[i].checked==true)
{
alert(document.getElementById('单选框id'));
}
}
------解决方案--------------------JScript code
var objArray = document.getElementsByName("collecta");
for (int i = 0; i < a=objArray.length; i++) {
if (objArray[i].checked) {
alert(objArray[i].value);
}
}
------解决方案--------------------
JScript code
var domArray = document.getElementsByName("collecta");
for (var i = 0; i < domArray.length; i++)
{
if (domArray[i].checked)
{
alert(domArray[i].value);
}
}