我刚开始在我的 mvc 应用程序的 jqmodals 中使用 jquery 小部件。
最初,
- 我可以单击添加链接,获取警报(“这是奖品”),然后单击取消以关闭所需结果的模式。
- 然后,我可以单击“编辑”链接并获得相同的所需结果。
- 但是,如果我先单击编辑链接,然后尝试单击添加链接,“忘记它”我没有收到警报(这意味着我的小部件没有初始化)。
- 但是我仍然可以返回并单击编辑并获得奖品(警报消息)。
ajax: "/Home/EditPrintAdLine" 和 ajax: "/Home/AddPrintAdLine" 最终将呈现相同的 Web 用户控件,其中包含初始化小部件的元素(字段名称为 PrintAdLine_RunDate)
有任何想法吗?
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<asp:Content ID="indexTitle" ContentPlaceHolderID="TitleContent" runat="server">
Home Page
</asp:Content>
<asp:Content ID="indexContent" ContentPlaceHolderID="MainContent" runat="server">
<div id="printAdLineEditDialog" class="jqmWindow"></div>
<div id="printAdDialog" class="jqmWindow"></div>
<table>
<tr><td><a id="printAdLineItem" href="#">Add a Line Item</a></td></tr>
<tr><td><a id="editPrintAdLine" href="#">Edit</a></td></tr>
</table>
<script type="text/javascript">
$(document).ready(function() {
$.widget("ui.my_widget", { _init: function() { alert("My widget was instantiated"); } });
// Add line
$('#printAdDialog').jqm({
ajax: "/Home/AddPrintAdLine",
trigger: '#printAdLineItem',
onLoad: function(hash) {
$('#PrintAdLine_RunDate').my_widget();
}
});
// Edit line
$('#printAdLineEditDialog').jqm({
ajax: "/Home/EditPrintAdLine",
trigger: '#editPrintAdLine',
onLoad: function(hash) {
$('#PrintAdLine_RunDate').my_widget();
}
});
});
</script>
</asp:Content>