首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >两次调用外部js

两次调用外部js
EN

Stack Overflow用户
提问于 2013-01-03 23:51:32
回答 1查看 617关注 0票数 0

是否可以在一个html文档中使用两次外部js文件和jquery?我运行了第一个函数,但是第二个函数调用不起作用。此外,外部js在Internet Explorer中打开时也不起作用。

代码语言:javascript
复制
<!DOCTYPE html >
<html>
<head>

<link href="css/stylesheetelaine.css" rel="stylesheet" type="text/css"/> 




<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.min.js"></script>

<script type="text/javascript" src="js/script2.js"> </script>

<script src="js/jQuery/jquery.monte.js"></script>     



<meta charset="utf-8">
<title>Gallery</title>


</head>

<body>

<div id="wrapper">

<div id="title">

<h1><a href="index.html"><img src="img/elaine4.png"  width="517" height="185" alt="elaine cullinan"></a><img src="img/elainefilligree.png" width="235" height="251" alt="elaine"></h1>


<div id="nav">
<ul id>

<li><a href="about.html" title="About">About</a></li>
<li><a href="tattoo.html" title="Tattoo">Tattoo</a></li>
<li><a href="makeup.html" title="Make Up">Make Up</a></li>
<li><a href="gallery.html" title="Gallery">Gallery</a></li>
<li><a href="contact.html" title="Contact">Contact</a></li>

</ul>
</div>
</div>

<div id="gallback">

<h2> Tattoos </h2>

<div id="gallerywrap">

    <div id='example1' class='container'>
        <img src="img/tattoogallery/outlineariel.jpg" alt='Zombie Ariel.'/>

        <img src="img/tattoogallery/horsecar.jpg" alt='Elaine tattooing'/>

        <img src="img/tattoogallery/2small.jpg" alt='Two Small Tattoos'/>

        <img src="img/tattoogallery/clown.jpg" alt='Clown'/>

        <img src="img/tattoogallery/lightsabers.jpg" alt='Finger Lightsabers'/>

        <img src="img/tattoogallery/flouder.jpg" alt='Flounder'/>

        <img src="img/tattoogallery/grenade.jpg" alt='Grenade'/>

        <img src="img/tattoogallery/colourcherryblossom.jpg" alt='Colour Cherry Blossom'/>
   <img src="img/tattoogallery/13.jpg" alt='13'/>

   <img src="img/tattoogallery/mechwing.jpg" alt='Mechanical Wing'/>

   <img src="img/tattoogallery/qotsa.jpg" alt='QOTSA'/>

   <img src="img/tattoogallery/horsecartatt.jpg" alt='Carousel'/>

   <img src="img/tattoogallery/lovefinger.jpg" alt='Love finger tatt'/>

   <img src="img/tattoogallery/hakun.jpg" alt='Hakuna Matata'/>

   <img src="img/tattoogallery/romannum.jpg" alt='Roman Numerals'/>

   <img src="img/tattoogallery/slayer.jpg" alt='Slayer'/>

   <img src="img/tattoogallery/shamrock.jpg" alt='Shamrock'/>

   <img src="img/tattoogallery/scriptarm.jpg" alt='Script'/>

   <img src="img/tattoogallery/skull.jpg" alt='Skull'/>

   <img src="img/tattoogallery/wristfoot.jpg" alt='Wrist and Foot Tatts'/>

   <img src="img/tattoogallery/zombieariel.jpg" alt='Zombie Ariel'/>

   <img src="img/tattoogallery/script.jpg" alt='Script'/>

   <img src="img/tattoogallery/chinese.jpg" alt='Chinese Symbols'/>

   <img src="img/tattoogallery/colflower.jpg" alt='Flower'/>

   <img src="img/tattoogallery/scriptfoot.jpg" alt='Foot Script Tatt'/>

   <img src="img/tattoogallery/Triton.jpg" alt='Triton'/>

   <img src="img/tattoogallery/zombiefingers.jpg" alt='Zombie Finger Tatt'/>

   <img src="img/tattoogallery/tyler.jpg" alt='Script'/>

   <img src="img/tattoogallery/3ursula.jpg" alt='Ursula'/>

   <img src="img/tattoogallery/locket.jpg" alt='Locket'/>

   <img src="img/tattoogallery/mechwing2.jpg" alt='Mechanical Wings'/>

   <img src="img/tattoogallery/backscript.jpg" alt='Script'/>

   <img src="img/tattoogallery/wingcolor.jpg" alt='Coloured Wing'/>


    </div>

 </div>


</div>


<div id="gallback">

<h2> Make Up </h2>

<div id="gallerywrap">

    <div id='example1' class='container'>
        <img src="img/tattoogallery/outlineariel.jpg" alt='Zombie Ariel.'/>

        <img src="img/tattoogallery/horsecar.jpg" alt='Elaine tattooing'/>

        <img src="img/tattoogallery/2small.jpg" alt='Two Small Tattoos'/>

        <img src="img/tattoogallery/clown.jpg" alt='Clown'/>

        <img src="img/tattoogallery/lightsabers.jpg" alt='Finger Lightsabers'/>

        <img src="img/tattoogallery/flouder.jpg" alt='Flounder'/>

        <img src="img/tattoogallery/grenade.jpg" alt='Grenade'/>

        <img src="img/tattoogallery/colourcherryblossom.jpg" alt='Colour Cherry Blossom'/>



    </div>

</div>


</div>



</div>
</body>

</html>

外部:

代码语言:javascript
复制
        $(function () {
            // Unstyled Example
            $.monte('#example1');


            // Styled Buttons Example
            // (see the CSS in the above style block)
            $.monte('#example2', {auto:false});


            // Callback Example
            // Format and append the HTML:
            $('#example3 > img').each(function(){
                $(this)
                .wrap('<div style="position:relative"/>')
                .parent()
                .append('<div><p>' + $(this).attr('alt') + '</p></div>')
                .append('<img src="frame.png" alt="" class="frame"/>');
            });
            // Hide the text on all but the center slide:
            $('#example3 div div').css({opacity: 0}).eq(0).css({opacity: 0.8});
            // Using the callbacks to reveal and hide the text:
            $.monte('#example3', {
                auto:false,
                callbackIn: function () {
                    $(this[0]).find('div').animate({opacity: 0.8}, 450);
                }, 
                callbackAway: function () {
                    $(this[0]).find('div').animate({opacity: 0}, 450);
                }
            });
        });
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-01-04 00:04:29

不要使用相同的ID创建多个DOM对象。ID应该是唯一的标识符。当您多次使用相同的ID时,很可能只对具有相同ID的第一个对象有效。

重命名该ID并使用新ID调用它。

代码语言:javascript
复制
    <!DOCTYPE html >
<html>
<head>

<link href="css/stylesheetelaine.css" rel="stylesheet" type="text/css"/> 




<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.min.js"></script>

<script type="text/javascript" src="js/script2.js"> </script>

<script src="js/jQuery/jquery.monte.js"></script>     



<meta charset="utf-8">
<title>Gallery</title>


</head>

<body>

<div id="wrapper">

<div id="title">

<h1><a href="index.html"><img src="img/elaine4.png"  width="517" height="185" alt="elaine cullinan"></a><img src="img/elainefilligree.png" width="235" height="251" alt="elaine"></h1>


<div id="nav">
<ul id>

<li><a href="about.html" title="About">About</a></li>
<li><a href="tattoo.html" title="Tattoo">Tattoo</a></li>
<li><a href="makeup.html" title="Make Up">Make Up</a></li>
<li><a href="gallery.html" title="Gallery">Gallery</a></li>
<li><a href="contact.html" title="Contact">Contact</a></li>

</ul>
</div>
</div>

<div id="gallback">

<h2> Tattoos </h2>

<div id="gallerywrap">

    <div id='example1' class='container'>
        <img src="img/tattoogallery/outlineariel.jpg" alt='Zombie Ariel.'/>

        <img src="img/tattoogallery/horsecar.jpg" alt='Elaine tattooing'/>

        <img src="img/tattoogallery/2small.jpg" alt='Two Small Tattoos'/>

        <img src="img/tattoogallery/clown.jpg" alt='Clown'/>

        <img src="img/tattoogallery/lightsabers.jpg" alt='Finger Lightsabers'/>

        <img src="img/tattoogallery/flouder.jpg" alt='Flounder'/>

        <img src="img/tattoogallery/grenade.jpg" alt='Grenade'/>

        <img src="img/tattoogallery/colourcherryblossom.jpg" alt='Colour Cherry Blossom'/>
   <img src="img/tattoogallery/13.jpg" alt='13'/>

   <img src="img/tattoogallery/mechwing.jpg" alt='Mechanical Wing'/>

   <img src="img/tattoogallery/qotsa.jpg" alt='QOTSA'/>

   <img src="img/tattoogallery/horsecartatt.jpg" alt='Carousel'/>

   <img src="img/tattoogallery/lovefinger.jpg" alt='Love finger tatt'/>

   <img src="img/tattoogallery/hakun.jpg" alt='Hakuna Matata'/>

   <img src="img/tattoogallery/romannum.jpg" alt='Roman Numerals'/>

   <img src="img/tattoogallery/slayer.jpg" alt='Slayer'/>

   <img src="img/tattoogallery/shamrock.jpg" alt='Shamrock'/>

   <img src="img/tattoogallery/scriptarm.jpg" alt='Script'/>

   <img src="img/tattoogallery/skull.jpg" alt='Skull'/>

   <img src="img/tattoogallery/wristfoot.jpg" alt='Wrist and Foot Tatts'/>

   <img src="img/tattoogallery/zombieariel.jpg" alt='Zombie Ariel'/>

   <img src="img/tattoogallery/script.jpg" alt='Script'/>

   <img src="img/tattoogallery/chinese.jpg" alt='Chinese Symbols'/>

   <img src="img/tattoogallery/colflower.jpg" alt='Flower'/>

   <img src="img/tattoogallery/scriptfoot.jpg" alt='Foot Script Tatt'/>

   <img src="img/tattoogallery/Triton.jpg" alt='Triton'/>

   <img src="img/tattoogallery/zombiefingers.jpg" alt='Zombie Finger Tatt'/>

   <img src="img/tattoogallery/tyler.jpg" alt='Script'/>

   <img src="img/tattoogallery/3ursula.jpg" alt='Ursula'/>

   <img src="img/tattoogallery/locket.jpg" alt='Locket'/>

   <img src="img/tattoogallery/mechwing2.jpg" alt='Mechanical Wings'/>

   <img src="img/tattoogallery/backscript.jpg" alt='Script'/>

   <img src="img/tattoogallery/wingcolor.jpg" alt='Coloured Wing'/>


    </div>

 </div>


</div>


<div id="gallback">

<h2> Make Up </h2>

<div id="gallerywrap2">

    <div id='example2' class='container'>
        <img src="img/tattoogallery/outlineariel.jpg" alt='Zombie Ariel.'/>

        <img src="img/tattoogallery/horsecar.jpg" alt='Elaine tattooing'/>

        <img src="img/tattoogallery/2small.jpg" alt='Two Small Tattoos'/>

        <img src="img/tattoogallery/clown.jpg" alt='Clown'/>

        <img src="img/tattoogallery/lightsabers.jpg" alt='Finger Lightsabers'/>

        <img src="img/tattoogallery/flouder.jpg" alt='Flounder'/>

        <img src="img/tattoogallery/grenade.jpg" alt='Grenade'/>

        <img src="img/tattoogallery/colourcherryblossom.jpg" alt='Colour Cherry Blossom'/>



    </div>

</div>


</div>



</div>
</body>

</html>

在makeup部分下,我将其重命名为gallerwrap2下的Gallery2。对于未设置样式的示例,您应该调用$.monte('#example2');

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14142315

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档