我在特定视图中添加了MvcContrib网格。在网格中,与列数据一起,我还有一个radiobutton列。我正在尝试选择radiobutton点击事件,但它没有按预期发生。我不知道实施有什么问题。你们可以看看并给出一些建议或代码片段来解决这个问题。
<%= Html.Grid(Model.Items)
.Columns(column =>
{
column.For(x => x.Name)
.Named(Html.OrderBy(null, "DisplayRestaurantsList", "Group", ViewContext.RouteData.Values, "sortBy", "sortDir", true, Model.SortDirection, Model.SortBy, "restaurantname", "Restaurant"));
column.For(x => x.Contact.GetDisplayName())
.Named(Html.OrderBy(null, "DisplayRestaurantsList", "Restaurant", ViewContext.RouteData.Values, "sortBy", "sortDir", true, Model.SortDirection, Model.SortBy, "administrator", "Administrator"));
column.For(x => Html.ActionLink("Remove", "RemoveRestaurant", "Group", new { id = x.ID, GroupID=x.Group.ID }, null))
.DoNotEncode();
column.For(x => Html.RadioButton("defaultRastaurant",x.ID,(!x.Group.ID.Value.ToString().IsEmptyOrNull() && x.ID==x.Group.DefaultRestaurantID) ? true:false)).Named("default").DoNotEncode();
})
.Attributes(@class => "table-1 gapmb40")
.Empty("There are no restaurants that match your criteria.")
.RowStart(row => string.Format("<tr{0}>", row.IsAlternate ? "style=\"background-color:#CCDDCC\"" : ""))
%>
用于选择单选按钮的jQuery代码:
$("input[type='radio']").click(function () {
alert("kaustubh");
});
也尝试过以下一个:
$("input[name='defaultRastaurant']").change(function () {
alert("kaustubh");
});
答案 0 :(得分:1)
看起来像事件委派问题。当事件处理程序与它关联时,该元素不存在于DOM中。
试试这个
$("body").on("click"," input[type='radio']" ,function () {
alert("kaustubh");
});
身体可以被任何存在无线电按钮的非静态父代替。