【发布时间】:2015-04-15 09:18:25
【问题描述】:
我花了几个小时寻找答案,但似乎无法完成这项工作。 我知道 asp.net 中的 javascript/jquery 仅在您有更新面板的情况下才首次工作,所以当您在 gridview 上页面时我也需要它来工作。 我发现您需要在更新面板中放置一些代码以在每次回发时刷新 javascript。 所以这是我尝试过的代码,它不起作用(给出'BindEvents not defined'错误)
这是不起作用的代码(短):
<asp:UpdatePanel runat="server" ID="updatePanel1" UpdateMode="Conditional">
<ContentTemplate>
<script type="text/javascript">
Sys.Application.add_load(BindEvents); ' reload jquery again after postback
</script>
<div id="div_GRIDVIEW" class="div_Gridview" clientidmode="Static" runat="server">
<asp:GridView ID="GridView1">
...grid data
</asp:GridView>
</div>
some more code....
<script type="text/javascript">
function BindEvents() {
$("table.STD_GridView tr").mouseover(function (event) {
var color = $(this).css("background-color");
$(this).css("background", "#f6f6f6");
$(this).bind("mouseout", function () {
$(this).css("background", color);
})
}
)
}
</script>
</body>
</html>
但是,如果您在更新面板中添加脚本 区域如下,它完美地工作。问题是我不想将 javascript/jquery 代码放在更新面板中,而是放在底部,因为我有很多 javascript/jquery 代码(这里只是一个示例)
任何指导将不胜感激
<asp:UpdatePanel runat="server" ID="updatePanel1" UpdateMode="Conditional">
<ContentTemplate>
<script type="text/javascript">
Sys.Application.add_load(BindEvents); ' triggers jquery again after postback of gridview'
function BindEvents() {
$("table.STD_GridView tr").mouseover(function (event) {
var color = $(this).css("background-color");
$(this).css("background", "#f6f6f6");
$(this).bind("mouseout", function () {
$(this).css("background", color);
})
}
)
}
</script>
<div id="div_GRIDVIEW" class="div_Gridview" clientidmode="Static" runat="server">
【问题讨论】: