jQuery ajax load() javascript not executing?

后端 未结 8 1123
执念已碎
执念已碎 2020-11-29 07:49

I\'ve read several posts about this issue but i can\'t solve it.

I am loading an html file into a div. The file i am loading contains a unordered list. This list sho

8条回答
  •  伪装坚强ぢ
    2020-11-29 08:24

    So lets make sure you have jQuery loaded in the first place, be sure that the link to the library is in the head of your HTML, so something like this:

    
    

    Use firebug to make sure it is loaded by checking the "net" tab.

    Also be sure you are loading your javascript: (here I've called it "main")

    
    

    Then in your js file do something like:

    $.(document).load( function () {
      alert("loaded!")
    });
    

    That should fire the alert once the page has "fully loaded" I prefer to use ready() which will fire once the DOM is loaded.

    If you have this all working and what you actually want to do is load and execute js from your js file try this:

    .getScript()
    

    This will load and execute the JavaScript you want.

提交回复
热议问题