how to manipulate, on document.ready, elements which were created on document.ready

后端 未结 2 903
轮回少年
轮回少年 2021-01-26 02:25

Here\'s the scenario: I have a menubar.js script, which, when the page loads, queries the server for user\'s permissions, and then creates a menubar based on them. code snippet:

相关标签:
2条回答
  • 2021-01-26 02:43

    My solution for the problem was to generate JavaScript which reads:

     var BASE_URL = 'http://server/app/...'
    

    All my URLs are either absolute or relative to BASE_URL. That way, I can simply look for all links which go to the current page and add the class "current" to them (take the URL for the current page, cut BASE_URL away and use the resulting string to query for a[href="..."]

    For your solution, I think the problem is that you run SetCurrentPage() after the page has loaded when you should call it after the "load menu" AJAX call has come back.

    Move the calls to the two methods to the end of the success callback in InitializeCurrentUser() and it should work.

    0 讨论(0)
  • 2021-01-26 02:43

    you forgot var before currentPage

    $(function() {
    
        //set this page as the current page; 
       var  currentPage = Enum.Page.Reports;
    });
    

    make sure that your function SetCurrentPage is being called after dom.ready event

    0 讨论(0)
提交回复
热议问题