如何保存单选按钮的值。朋友已经做了这个以获得一个cookie。 现在我需要进入下一步,但我不知道如何。
function saveForm(nForm){
var nFields = nForm.length;
for (i=0; i<nFields; i++)
{
var isType = nForm[i].type;
alert(isType);
if (isType == 'radio'){alert('Field '+ i+ ' is a radio button')}
if (isType == 'select-one'){alert('Field '+i + ' is a select list')}
}
}
<form onsubmit="return saveForm(this)">
<input type = "radio" name = "staande_houding_globaal" value="0">
0 </input>
<input type = "radio" name = "staande_houding_globaal" value="1">
1 </input>
<input type = "radio" name = "staande_houding_globaal" value="2">
2 </input>
<input type = "radio" name = "staande_houding_globaal" value="3">
3 </input>
<input type = "radio" name = "staande_houding_globaal" value="4">
4 </input>
<input type = "radio" name = "staande_houding_globaal" value="5">
5 </input>
<input type = "radio" name = "staande_houding_globaal" value="6">
6 </input>
<input type = "radio" name = "staande_houding_globaal" value="7">
7 </input>
<input type="button" value="Volgende" onClick="history.forward()","saveState()" class = "volgende" />
</form>
答案 0 :(得分:0)
获取单选按钮的值尝试
$("input:radio[name=staande_houding_globaal]").click(function() {
alert($(this).val());
});
或强>
var xyz = $("input[name=staande_houding_globaal]:checked").val();
console.log(xyz);
使用此选项检查单选按钮是否已选中
$('input[name=staande_houding_globaal]').is(":checked");
这将返回一个布尔值