做项目时,遇到这个问题:
<td nowrap="nowrap">*是否发布:</td>
<td>
<input type="radio" name="articleStatus" id="articleStatusYes" <c:if test="${article.articleStatus ==3 }">checked="checked"</c:if> value="3"/>是
<input type="radio" name="articleStatus" id="articleStatusNo" <c:if test="${article.articleStatus !=3 and article.articleStatus != null}">checked="checked"</c:if> value="0"/>否
</td>
解决方案:$("input[name='articleStatus']:checked").val() 可以直接获取单选按钮的值,如果没选则为空!
也可以:
var temp = document.getElementsByName("radHot"); for(var i=0;i<temp.length;i++) { if(temp[i].checked) var intHot = temp[i].value; }