如何通过jQuery发布单选按钮值 [英] how to POST radio button values through jquery
本文介绍了如何通过jQuery发布单选按钮值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下示例代码:
while ($row = mysql_fetch_object($result1)) {
echo '<input type="radio" name="vote" value='.$row->avalue.'/> ';
echo '<label >'.$row->atitle.'</label><br>';
}
这将显示4个单选按钮及其标签. 现在,我正在使用以下jquery函数进行POST.
this displays 4 radio buttons alongwith their labels. now I am using the following jquery function to POST.
$("#submit_js").click(function() {
$.post(
"user_submit.php",
{//how to POST data?},
function(data){
});
});
我要发布与单选按钮关联的值.但是我该如何选择值呢? 我如何确定选择了哪个单选按钮并发布它?
I want to post the value associated with the radio button. but how do i select the value? how do i determine what radio button is selected and POST it?
推荐答案
$("[name='vote']:checked").val()
将为您提供所选单选按钮的值.
$("[name='vote']:checked").val()
will get you the value of the selected radio button.
$("#submit_js").click(function() {
$.post(
"user_submit.php",
{vote: $("[name='vote']:checked").val()},
function(data){
});
});
这篇关于如何通过jQuery发布单选按钮值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文