我有下面的代码在 asp.net 中有智能下拉列表,在那里有搜索属性
<script type="text/javascript"> $(".chzn-select").chosen(); $(".chzn-select-deselect").chosen({ allow_single_deselect: true }); </script>
问题是每当我以这种方式使用 updatepanel 时:
<asp:UpdatePanel ID="UpdatePanel1" runat="server" >
<ContentTemplate>
<fieldset>
</fieldset>
</ContentTemplate>
</asp:UpdatePanel>
在那之后:它失去了它的属性并作为正常的下拉列表返回。知道如何解决这个问题并使更新面板不重新创建下拉列表到它以前的属性吗?!
最佳答案
您需要在 UpdatePanel 更新后再次执行该脚本。由于 DOM 仍在变化并且浏览器丢失了脚本绑定(bind)。为此,您可以使用 PageRequestManager
。
<script type="text/javascript">
var prm = Sys.WebForms.PageRequestManager.getInstance();
//for after an updatepanel update
prm.add_endRequest(function () {
buildDropDownList();
});
//for normal page load
buildDropDownList();
function buildDropDownList() {
$(".chzn-select").chosen();
$(".chzn-select-deselect").chosen({ allow_single_deselect: true });
}
</script>
关于javascript - 在 asp.net 中使用 updatePanel 后,DropDownList 丢失其属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51584624/