javascript - 为什么js文件中的变量值被删除。当我打开 jquery fancy box 时?

标签 javascript jquery html

我有两个 .js 文件和一个 HTML。我将变量的值从一个 .js 文件初始化到另一个 .js 文件。在 HTML 文件中,我有一个 Jquery 精美的框。当我打开 Jquery 精美的盒子时。初始化的 valriable 被删除了,我不知道为什么。请帮忙解决。

JS:

function createEventDlg() {
      $.fancybox({
             href: "events/createEvent",
             type: "iframe", // <-- whatever content image, inline, swf, etc
             width: 600,
             afterClose: openEventImageUpdate
      });
   }

HTML:

<ul  class="nav navbar-nav navbar-left">
                            <li class="li-search-logged">
                            <!-- id="selectedValueId" -->
                                <select  id="selectSearch">
                                    <option selected>Events</option>
                                    <option>Connections</option>
                                    <option>DFA Users</option>
                                </select>
                                <input type="text" id="auto-complete-tag" class="form-control" placeholder="Find Events, People, and Connections" />
                                <button class="btn btn-positive" type="button"></button>
                            </li>
                            <li class="li-btn"><input type="button" value="Create" class="btn btn-positive" onclick='createEventDlg();' /></li>
                            <li class="li-btn"><input type="button" value="Browse" class="btn btn-positive" onclick="loadBrowseEventPage()" /></li>
                            <li class="li-btn"><input type="button" value="DFA" class="btn btn-positive" onclick="loadDFA()" /></li>
                        </ul>

浏览.js:

这里 appRootUrl 变量有一个值。例如:“/app”,它调用通知中的方法。 js 的 init() 方法。然后Notifications.js的对象被初始化。我的问题是当我打开 jquery fancy box 时。初始化的变量值被删除,为什么我不知道。我将使用这个变量值进行 Jquery ajax 调用。因为我在notifications.js中有很多方法。这些方法将使用该变量值。请帮我。

 $( document ).ready(function() {
  <%
 ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
  Properties properties = new Properties();
  properties.load(classLoader.getResourceAsStream("app.properties"));
  %>
  var te = '${appRootUrl}';
  console.log('App root ulr : ' + te);
  notifications.init('${appRootUrl}', "<%= properties.getProperty("node.server")%>");    
});

通知.js:

var notifications = {
    appRootUrl : "something",
    nodeServer : "something",
    resource: {
        user: {
            findById: "/users/findbyid",
            getAlerts: "/users/getalerts",
            acceptChat: "/users/acceptchatinvite",
            declineChat: "/users/declinechatinvite",
            acceptFriend: "/users/acceptconnectioninvite",
            declineFriend: "/users/declineconnectioninvite",
            clearAlert: "/users/clearAlert",
            get: "/users/getuser",
            getEventPrivateChatHistory: "/users/eventPrivateChatHistory",
            eventPrivateSend: "/users/eventPrivatesend",
            dfaSend: "/users/dfasend",
            eventRestart: "/users/eventrestart",
            getFriendState: "/users/getFriendState",
            getDfaHistory: "/users/dfahistory",
            makeUserRelationshipNone: "/users/makerelationshipnone"
        },
        event: {
            getEventApprovedUsers: "/events/getApprovedUsers",
            getDfaGroupChatHistory: "/events/getGroupchatHistory",
            updateGroupChatMsgUrl: "/events/saveGroupchat",
            get: "/events/getEvent"
        }
    },
    init: undefined
};

notifications.init = function (appRootUrl, nodeServer) {
    console.log('appRootUrl : ' + appRootUrl);
    console.log('nodeServer : ' + nodeServer);

    notifications.appRootUrl = appRootUrl;
    notifications.nodeServer = nodeServer;
    console.log('notifications : ' + JSON.stringify(notifications));
};

最佳答案

最后我发现答案是我必须初始化 Jquery 奇特框中的值。因为 Jquery fancy box 充当当前的 JSP。在从 browser.jsp 初始化之前。当用户单击 Jquery 花式框时。它加载 JqueryFancyBox.JSP 文件。我必须在那里初始化该值。

示例代码在这里:

JqueryFancyBox.jsp:

<c:url var="appRootUrl" value="/"/>
$(function () {
            <%
            ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
            Properties properties = new Properties();
            properties.load(classLoader.getResourceAsStream("app.properties"));
            %>
            notifications.init("${appRootUrl}", "<%= properties.getProperty("node.server")%>");
});

关于javascript - 为什么js文件中的变量值被删除。当我打开 jquery fancy box 时?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40193243/

相关文章:

javascript - 如何使用 Tampermonkey 删除 CSS 类?

html - 使整个 div 可点击,而不是其中的链接

javascript - asp.net mvc ModelState IsValid - 有效处理 false 的返回

javascript - 将页面上的 JSON 数据显示为可展开/可折叠列表

javascript - 在 ngRepeat 中过滤嵌套属性

javascript - 当我单击向上和向下箭头时,选择了下拉列表中的样式 ="display:none"选项

c# - 如何将 System.IO.Packaging.Package 转换为 HTML?

javascript - 由 javascript 更改时 SVG 过渡到点

javascript - css3 过渡开始点击

javascript - jquery 替换 DIV 数据,然后跟踪点击它