I'm setting up a page that uses a flash menu to load html pages into a div container by the following call:
on (release){
getURL("javascript:getPage('test.html')");
}
The loading works fine, but some of my pages had specific jquery scripts and that's where I've struck out so far.
I assumed all I needed to do was transfer the script importations, css stylesheets and the jquery functions to my main document, but it won't work.
I also tried importing the html as a the complete html, which works on it's own, but not when imported into the main document.
Most recently I heard I should try shifting the jquery function calls to the end of the loaded document, to after the content, but that didn't help either...
My scripts work, just not when imported, so I suppose my question is how can I make the main- and imported documents play nice with each other? What say you we ma开发者_运维技巧ke this a jump-start tutorial for all us noobs to reference?
So it depends on what the scripts on the loaded page is doing, you can look at the live() function in jQuery.
Alternatively you can make use of a callback function in your AJAX call to set up the jquery event handling for the loaded page.
Using the ready() command often helps things (it is a Dom listener) as well as moving code to the bottom, which some will argue makes the page load more efficient (a point for another post)
However, this question comes up a lot and 9 times out of 10 it's related to the script or Jquery link itself being invalid in the page that it's included from. For example, if the page doing the jquery is in the /scripts folder and it calls jquery.js that also resides in the /scripts folder, it works. However, when you include the file into index.htm that resides in the / folder, suddenly the link to jquery is looking for a jquery file in /, not in /scripts. The easy way to check this is to view source and click on the links (works great in Chrome) to see if the files are found. If so, you're good...if not, play with your link paths. Better yet, use CDN hosted versions of code when possible.
And, for noobs, it is possible to include jQuery in files outside of the document head and they still work just fine. My company uses that method on webforms that get included via (ugh) iFrame in other's sites. It's serving up hundreds of webforms flawlessly!
One last thing. As a UI engineer for many years, I've been seeing a very clear trend of Flash menus really dying off in a hurry (which is also followed by a serious drop-off in Flash developer hiring) They often have serious SEO issues, take more effort to maintain, and can have other performance implications. Chances are these days that you can get a Javascript, pure CSS, or HTML5 menu that does the same thing or better and is 100% w3 compliant. Maybe personal preference, but definitely a growing trend to consider as you continue to learn.
精彩评论