How can I make a function defined in jQuery.ready available globally?

后端 未结 6 1730
悲&欢浪女
悲&欢浪女 2020-12-04 08:17

I have a function that strips the youtube id off a url. I then want to use this function 10 time per page (in the wordpress loop).

The function works great when I fe

6条回答
  •  独厮守ぢ
    2020-12-04 08:35

    declare getList() outside the ready() function..

    var getList = function(url, gkey){
            var returned = null;
            if (url.indexOf("?") != 
    ....
    ....
    ...
    };
    

    Now the getList will work anywhere in the code:

    $(document).ready( function() {
    alert(getList('http://www.youtube.com/watch?v=dm4J5dAUnR4', "v"));
    });
    

    The problem was, scope of the getList(.) function.

提交回复
热议问题