【发布时间】:2015-07-28 16:34:42
【问题描述】:
<script type="text/javascript">
function radio_form(){
var selectvalue = $('input[name=choice]:checked', '#radio_form').val();
if(selectvalue == "V1"){
alert('Value 1');
return true;
}else if(selectvalue == "V2"){
alert('Value 2');
return true;
}else if(selectvalue == 'V3'){
alert('Value 3');
return true;
}else if(selectvalue == 'V4'){
alert('Value 4');
return true;
}
return false;
};
</script>
<form id="radio_form">
<input type="radio" onclick="radio_form()" name="choice" value="V1">
<input type="radio" onclick="radio_form()" name="choice" value="V2">
<input type="radio" onclick="radio_form()" name="choice" value="V3">
<input type="radio" onclick="radio_form()" name="choice" value="V4">
</form>
我试图在选择单选值时显示警报...但是这种方法似乎不起作用。
我是不是做错了什么?
【问题讨论】:
-
如果你使用 jquery,你只需要 ($(this).val()) 和一个点击函数 -- 演示 -- jsfiddle.net/z66fbof2
-
@TasosAnastasiou 我可以重定向到一个网址吗?
-
来自我假设的电台选择??是的,将值更改为“somesite.com”并查看下面的答案
标签: javascript jquery if-statement radio-button