我有3個單選按鈕。我想要這樣的邏輯:當我按下單選按鈕 時,將調用所需的操作方法。我不知道如何用 JQuery。有沒有其他的變種?通過按單選按鈕呼叫操作方法
<h3>Gender:</h3>
@Html.RadioButton("Gender", "All", true, new {id = "radioAll"})
@Html.Label("All")
<br/>
@Html.RadioButton("Gender", "Male", false, new {id = "radioMale"})
@Html.Label("Male")
<br/>
@Html.RadioButton("Gender", "Female", false, new {id = "radioFemale"})
@Html.Label("Female")
// I tried to find out a decision but couldn't.
<script>
$(document).ready(function() {
var url = '@Url.Action("ShowUsers", "Home")';
if ($("#radioMale").attr("checked") === "checked") {
$.post(url, 'choice=' + "Male");
}
});
</script>
什麼樣的行動必須調用方法?獲取或發佈? –
'$ .post'僅適用於POST方法。但數據應該像關鍵值pari'{choice:choice}',參見[this](http://api.jquery.com/jquery.post/)表單更多信息 –