我是MVC的新手,並試圖拋光webgrid
的概念。我在view
JavaScript不工作在排序或分頁後的MVC webgrid
@model IEnumerable<MVCMovies.Models.Movie>
@{
ViewBag.Title = "Index";
}
<script type="text/javascript">
$(function() {
$('tbody tr').on('hover', (function() {
$(this).toggleClass('clickable');
}));
$('tbody tr').on('click', (function() {
alert('rajeev');
}));
});
</script>
<style type="text/css">
.table {
margin: 4px;
width: 100%;
background-color: #FCFCFC;
}
.head {
background-color: #11E8CD;
font-weight: bold;
color: #CC6699;
}
.webGrid th, .webGrid td {
border: 1px solid #C0C0C0;
padding: 5px;
color:white;
}
.altRow {
background-color: #E4E9F5;
color: #000;
}
.gridHead a:hover {
text-decoration: underline;
}
.description {
width: auto;
}
.selectRow {
background-color: #0B7BEB;
}
.clickable {
cursor: pointer;
background: #ffff99;
}
</style>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<div>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div style="float:left">Title : @Html.TextBox("SearchString")<br /> </div>
<div style="float:left; padding-left:5px">
<input type="button" value="Filter" class="btn" />
</div>
}
</div>
<div id="grid">
@{
var gd = new WebGrid(Model, rowsPerPage: 2, ajaxUpdateContainerId: "grid");
@gd.GetHtml(tableStyle: "table");
}
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
現在下面的代碼,我的jQuery編寫的代碼的點擊行functinon但它停止工作後,我整理或的WebGrid做分頁
運行代碼時出現什麼錯誤? – 2015-04-01 09:03:59
沒有錯誤,但JavaScript代碼停止工作.. I.e排序行後沒有alert msg點擊 – 2015-04-01 09:04:46
您是否動態更新錶行? - 如果是的話,使用事件委託 - '$(document).on('click','tr',(function(){...' – 2015-04-01 09:05:27