2011-11-09 6 views
-2

div IDのクリック機能を参照する外部jqueryファイルを呼び出そうとしています。この関数はhtmlページに埋め込まれているときにうまく機能しますが、私はすべてのjを外部的に呼びたいと思っています。ここでdivのIDを使用してdivから外部JQuery関数を呼び出す

は、外部JSファイルは、私の頭のタグである:

:ここpopuptabs.js

jQuery(function($) { 

     var open = false; 

     $('#footerSlideButton').click(function() { 

      if(open === false) { 

       $('#footerSlideContent').animate({ height: '300px' }); 

       $(this).css('backgroundPosition', 'bottom left'); 

       open = true; 

      } else { 

       $('#footerSlideContent').animate({ height: '0px' }); 

       $(this).css('backgroundPosition', 'top left'); 

       open = false; 

      } 

     });  

    }); 


     jQuery(function($) { 

     var open = false; 

     $('#footerSlideButton2').click(function() { 

      if(open === false) { 

       $('#footerSlideContent2').animate({ height: '300px' }); 

       $(this).css('backgroundPosition', 'bottom left'); 

       open = true; 

      } else { 

       $('#footerSlideContent2').animate({ height: '0px' }); 

       $(this).css('backgroundPosition', 'top left'); 

       open = false; 

      } 

     });  

    }); 


      jQuery(function($) { 

     var open = false; 

     $('#footerSlideButton3').click(function() { 

      if(open === false) { 

       $('#footerSlideContent3').animate({ height: '300px' }); 

       $(this).css('backgroundPosition', 'bottom left'); 

       open = true; 

      } else { 

       $('#footerSlideContent3').animate({ height: '0px' }); 

       $(this).css('backgroundPosition', 'top left'); 

       open = false; 

      } 

     });  

    }); 

ためで

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script> 

    <script type="text/javascript" src="js/popuptabs.js" charset="utf-8"></script> 

jQueryのコードは、私が参照してるのdivと私のhtmlです

<div id="footerSlideContainer"> 
    <div id="footerSlideButton"></div> 
    <div id="footerSlideContent"> 
     <div id="footerSlideText"> 
      <h3>Online Brochures</h3> 
      <p>Coming Soon!</p> 
     </div> 
    </div> 
</div> 

私はこれを試しました:<a href="JavaScript:popuptabs.click('footerSlideButton');"></a>私の部門で無駄です。この関数を呼び出す正しい方法がわからない。

+0

を:

<a id="someLinkId" href="#">Link Text.</a> 

をと言います実際に何が起こるか。 – BNL

+0

ここで間違っているのは何ですか? – JaredPar

+0

htmlページにコードを埋め込むとコードが正常に機能します。しかし、私は外部からクリック機能を呼びたいと思っています... – Shannon

答えて

0

理由だけではなく、あなたがid値からの関数を呼び出したいリンク与えていない:私はあなたのサンプルコードを簡素化し、についての詳細を与えることをお勧めしたい

$("#someLinkId").click(function() { 
    $('#footerSlideButton').trigger('click'); 
}); 
+0

助けてくれてありがとうが、残念ながらそれは動作しませんでした... – Shannon

関連する問題