在jquery中的函数中包装脚本标记

时间:2013-08-22 03:48:26

标签: jquery html

我想让这个功能正常工作。我试图让它执行函数只在单击li时读取xml

以下是我的jQuery:

     <script>
                $("ul.productcat li").on('click', function (e) {
                    var $this = $(this),
                        // Class of the one to be shown
                        subclazz = $this.data("class"); 
                        $('article > div').removeClass('show');
                        $('.' + subclazz).addClass('show');                  
                    mygallery(subclazz);
                });
            </script> 
            function mygallery(config){ 
            <script type="text/javascript" src="gallery/js/jquery.js"></script> 
            <script type="text/javascript" src="gallery/js/swfobject.js"></script> 
            <script type="text/javascript" src="gallery/js/flashgallery.js"></script> 
            <script type="text/javascript">
                jQuery.flashgallery('gallery/gallery.swf', 'gallery/'+config+'.xml', { width: '650px', height: '600px', background: 'transparent' });
            </script>
    }

任何帮助都将不胜感激。

2 个答案:

答案 0 :(得分:2)

你应该做的事情如下:

//load all the scripts
<script type="text/javascript" src="gallery/js/jquery.js"></script> 
<script type="text/javascript" src="gallery/js/swfobject.js"></script> 
<script type="text/javascript" src="gallery/js/flashgallery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
    $("ul.productcat li").on('click', function (e) {
        var $this = $(this),
        // Class of the one to be shown
        subclazz = $this.data("class");                   
        mygallery(subclazz);
    });
});
function mygallery( config ) {
    jQuery.flashgallery('gallery/gallery.swf', 'gallery/'+config+'.xml', { 
         width: '650px', 
         height: '600px', 
         background: 'transparent' 
    });
}
</script>

答案 1 :(得分:0)

  function mygallery(config){ 
<script type="text/javascript" src="gallery/js/jquery.js"></script> 
        <script type="text/javascript" src="gallery/js/swfobject.js"></script> 
        <script type="text/javascript" src="gallery/js/flashgallery.js"></script> 
        <script type="text/javascript">
            jQuery.flashgallery('gallery/gallery.swf', 'gallery/'+config+'.xml', { width: '650px', height: '600px', background: 'transparent' });
        </script>
}

改变

 function mygallery(config){  
jQuery.flashgallery('gallery/gallery.swf', 'gallery/'+config+'.xml',
 { width: '650px',
 height: '600px',
 background: 'transparent'
 }
);
}