2014-03-12 1 views
-1

자바 스크립트에 문제가 있습니다. 현재 잘 작동하는 두 개의 자바 스크립트 파일이 있지만 단일 파일로 결합하면 첫 번째 쿼리가 작동하고 두 번째 파일은 작동하지 않습니다.한 페이지에서 두 개의 자바 스크립트를 결합하는 방법은 무엇입니까?

$(document).ready(function() { 
    jcps.fader(200, '#switcher-panel2', '.set2'); 
    jcps.fader(300, '#switcher-panel3', '.set3'); 
    jcps.fader(400, '#switcher-panel4', '.set4'); 
    jcps.fader(500, '#switcher-panel5', '.set5'); 
}); 

$(document).ready(function() { 
    $("#lista1").als({ 
     visible_items: 3, 
     scrolling_items: 2, 
     orientation: "horizontal", 
     circular: "yes", 
     autoscroll: "no", 


     easing: "linear", 
     direction: "left", 
     start_from: 0 
    }); 

    //logo click 
    $("#logo_img").click(function() { 
     location.href = "http://als.musings.it/index.php"; 
    }); 

    $("a[href^='http://']").attr("target", "_blank"); 
    $("a[href^='http://als']").attr("target", "_self"); 
}); 
+0

그것은 jQuery를 버전 충돌 문제가 될 수 있습니다. 다른 jQuery 버전을 사용하고 있습니까? jQuery.noConfilict()를 제거하십시오. –

+0

은 같은 페이지에있는 두 개의 javascipt입니까? – SpiderCode

+0

문제는 귀하의 페이지에서 두 개의 $ (document) .ready()를 사용하고 있다는 것입니다. 그것의 insetead는 그것을 단지 한 번 정의하고, 모든 것을 그것 안에 넣는다. 내 대답을 똑같이 보아라. – SpiderCode

답변

0

이 매우 적은 정보입니다; "단일 페이지에 가입"한 그대로 코드를 제공 할 수 있습니까? 그게 당신 코드에있는 것입니까? HTML을 어디서 어떻게 작성합니까?

어쨌든, 내 첫번째 추측은 다음과 같이 두 기능을 통합하는 것입니다 : 도움이된다면

$(document).ready(function() { 
    jcps.fader(200, '#switcher-panel2', '.set2'); 
    jcps.fader(300, '#switcher-panel3', '.set3'); 
    jcps.fader(400, '#switcher-panel4', '.set4'); 
    jcps.fader(500, '#switcher-panel5', '.set5'); 

    $("#lista1").als({ 
     visible_items: 3, 
     scrolling_items: 2, 
     orientation: "horizontal", 
     circular: "yes", 
     autoscroll: "no", 


     easing: "linear", 
     direction: "left", 
     start_from: 0 
    }); 

    //logo click 
    $("#logo_img").click(function() 
    { 
     location.href = "http://als.musings.it/index.php"; 
    }); 

    $("a[href^='http://']").attr("target","_blank"); 
    $("a[href^='http://als']").attr("target","_self"); 
}); 

이 말해. 아래에 언급 한 바와 같이 귀하의 자바 스크립트

+0

고마워요 –

+0

도움이 되니 기쁩니다! 그럼 내 대답을 확인해 주시겠습니까? – Sheraff

0

업데이트 :

<script type="text/javascript" language="javascript"> 
    $(document).ready(function() { 

     SetFader(); 

     SetAttributes(); 

    }); 

    function SetFader() { 
     jcps.fader(200, '#switcher-panel2', '.set2'); 
     jcps.fader(300, '#switcher-panel3', '.set3'); 
     jcps.fader(400, '#switcher-panel4', '.set4'); 
     jcps.fader(500, '#switcher-panel5', '.set5'); 

    } 

    function SetAttributes() { 
     $("#lista1").als({ 
      visible_items: 3, 
      scrolling_items: 2, 
      orientation: "horizontal", 
      circular: "yes", 
      autoscroll: "no", 


      easing: "linear", 
      direction: "left", 
      start_from: 0 
     }); 

     //logo click 
     $("#logo_img").click(function() { 
      location.href = "http://als.musings.it/index.php"; 
     }); 

     $("a[href^='http://']").attr("target", "_blank"); 
     $("a[href^='http://als']").attr("target", "_self"); 

    } 

</script> 
관련 문제