无法检索单选按钮组中的选中值按钮
问题描述:
我正试图检索单选按钮组中已选中按钮的值。无法检索单选按钮组中的选中值按钮
<script type="text/javascript">
function ButtonClicked() {
alert($('input[name=datetype] :checked').val());
return;
}
</script>
<form action="test.php">
<input type="radio" value="d1" name="datetype" checked onclick="javascript: ButtonClicked()">Date 1 <br />
<input type="radio" value="d2" name="datetype" onclick="javascript: ButtonClicked()"> Date 2 <br />
</form>
输出总是'未定义'。我是jQuery(和JS)的初学者,所以我可能会漏掉一些明显的东西,但是看着大量的例子并没有帮助。
答
alert($('input[name=datetype]:checked').val());
尝试没有从一的onclick空间
答
删除 '的JavaScript'。
<input type="radio" value="d1" name="datetype" checked onclick="ButtonClicked()">Date 1 <br />
<input type="radio" value="d2" name="datetype" onclick="ButtonClicked()"> Date 2 <br />
答
多easyser:
<script type="text/javascript">
function ButtonClicked(value) {
alert(value);
return;
}
</script>
<form action="test.php">
<input type="radio" value="d1" name="datetype" checked onclick="javascript:ButtonClicked(this.value)">Date 1 <br />
<input type="radio" value="d2" name="datetype" onclick="javascript: ButtonClicked(this.value)"> Date 2 <br />
</form>
警报($( '输入[名称= datetype]:检查')。VAL());尝试没有空间 – benhowdle89 2010-12-07 11:19:40
@ benhowdle89:你应该添加作为答案。 – Matt 2010-12-07 11:21:01