开发者

using jquery on child page

开发者 https://www.devze.com 2022-12-18 18:28 出处:网络
if i load(\'mypage.htm\') into <div id=\"placeMyContent开发者_如何转开发Here\"> do i need to put JQuery in\"mypage.htm\". I\'m using color box ( of light box ike)on my child page. If i add jque

if i load('mypage.htm') into <div id="placeMyContent开发者_如何转开发Here">

do i need to put JQuery in "mypage.htm". I'm using color box ( of light box ike) on my child page. If i add jquery.js & colorbox.js into mypage.htm it works. Though i can't helping thinking there is better way.

Here is how i normally call colorbox

$(document).ready(function() {

$("a[rel='example1']").colorbox();


Use load's callback function to re-initialise colorbox, there is no need for a $(document).ready(... in the content you are injecting into your div, e.g.:

$("#placeMyContentHere").load('mypage.htm', function() {
    $("a[rel='example1']").colorbox();
});


You don need to include jquery and colorbox in child page. You are changing the DOM object therefore use jquery live

$("a[rel='example1']").live(function(){
   $(this).colorbox();
});


No, you should only include your javascript libraries (jQuery and plugins) once; on the main page.

0

精彩评论

暂无评论...
验证码 换一张
取 消