我試圖通過ajax傳遞值(單選按鈕)。發送的值錯誤。我有4個收音機,但窗體不斷髮送第一個值(== 1)。請你們給我一些建議。爲什麼發生?無法通過jquery發送無線電真實值ajax
這裏是我的代碼:
<ul class="nav nav-list">
<li><label for="1"><input type="radio" name="vote" id="1" class="choice" value="1"> Choice 1</label></li>
<li><label for="2"><input type="radio" name="vote" id="2" class="choice" value="2"> Choice 2</label></li>
<li><label for="3"><input type="radio" name="vote" id="3" class="choice" value="3"> Choice 3</label></li>
<li><label for="4"><input type="radio" name="vote" id="4" class="choice" value="4"> Choice 4</label></li>
<li class="divider"></li>
<li>
<div id="vote_loading" style="display:none">loading...</div>
<div id="vote_result"></div><button class="btn btn-small btn-success" type="button" onClick = "voting()"><i class="icon icon-thumbs-up icon-white"></i> Vote</button>
</li>
</ul>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
//voting
function voting(){
var choice = $('.choice').val();
$.ajax({
type: "POST",
url: "inc/vote_chk.php",
data: {choice:choice}
}).done(function(result){
$("#vote_loading").slideUp("slow");
$("#vote_result").html(result).slideDown("slow");
});
}
</script>
通過我用引導的方式。但這與代碼無關。
Regards,
jsfiddle? (沒有ajax調用) –
這將幫助您開始:http://stackoverflow.com/questions/3464075/get-value-of-radio-button-group – BjornJohnson