forcing a jQuery ready block to run after all other ready blocks

后端 未结 4 1985
醉梦人生
醉梦人生 2021-01-02 00:10

Is it possible to have one jQuery ready block executed after all others have done so.

I have this in my master page ...



        
相关标签:
4条回答
  • 2021-01-02 00:24

    How about only you only registring one document.ready() on the master page, and then let that one execute the code based on a variable? This solution is not that elegant, but a search for JavaScript thread synchronization didn't really turn op anything.

    You could change the code on the master page to:

    <script type="text/javascript">
        var runWysiwyg = false;
        $(document).ready(function()
        {
            if (runWysiwyg) {
                $('textarea.message-body').wysiwyg();
            }
            $("input[type='text']:enabled:first", document.forms[0]).focus().select();
        });
    </script>
    

    And put this script in you page:

    <script type="text/javascript">
        runWysiwyg = true;
    </script>
    
    0 讨论(0)
  • 2021-01-02 00:25

    Add a custom event trigger to your master page:

    <script type="text/javascript">
    $(document).ready(function()
    {
        $('textarea.message-body').wysiwyg();
        $(document).trigger('tb');
    });
    </script>
    

    And bind it to the other page:

    <script type="text/javascript">
    $(document).bind('tb', function(){
      $("input[type='text']:enabled:first", document.forms[0]).focus().select();          
    });
    </script>
    

    References

    • jQuery Special Events...Virtually, not in Real Life

    • How to Create Custom Events in JavaScript

    • AOP Aspect of JavaScript

    0 讨论(0)
  • 2021-01-02 00:34

    $(window).load() function fires after the $(document).ready()

    0 讨论(0)
  • 2021-01-02 00:38

    This is the solution I went with.

    In my master page I have this...

    <script type="text/javascript">
    <!--
        $(document).ready(function()
        {
            if (typeof (OnLoad) != "undefined")
            {
                OnLoad();
            }
    
            $("input[type='text']:enabled:first", document.forms[0]).focus().select();
        });
    //-->
    </script>
    

    and in my detail pages I have this...

    <script type="text/javascript">
    <!--
        function OnLoad()
        {
            $('textarea.message-body').wysiwyg();
        }
    //-->
    </script>
    
    0 讨论(0)
提交回复
热议问题