在哪里声明javascript / jQuery脚本

I'm trying to do some stuff with jquery/js (I don't know which one it is..), for example this script ; http://pastebin.com/V3HpU0NY - > http://blog.mainstreethost.com/light-youtube-embeds-faster-page-load#.VG9HKamkVSJ

But now comes the difficult part.

Url: http://erwin.my89.nl/stage/sieh/

enter image description here This is the website when you go to the url.

This loads the "gallery (top)" and all content/ and kinda images(lazyload) for all the 'gallery' posts. If this has to be done another way please say so.

When you click a image you'll get this: enter image description here

I hope you understand the idea.

So everything working ok

but now i go in to the inspector and i encounter this?!

enter image description here

I assume it is because i have the script defined in the loop of the content.. so when i click a gallery image, it loads another bunch of those text/css's.

So my question is: Is this the right way to do it? or should i be doing this different?

while ($loop->have_posts()) : $loop->the_post($post->ID);
 if ($metas) {
      foreach ($metas as $metakey) {

        } elseif ($metakey['url']) {
            preg_match(
                '/[\\?\\&]v=([^\\?\\&]+)/',
                $metakey['url'],
                $matches
            );
            $id = $matches[1];

            ?>
            <div class="youtube" id="<?php echo $id ?>" style="width: 560px; height: 315px;"></div>
            <script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/youtube.js"></script>

        <?php

^part of the code, if need more please say so.

Thanks in advance!

1个回答

Can you put your CSS file/s in the head? That's where it normally goes.

Also, I don't see anywhere in your PHP where it could be loading these <style></style> tags. However it does look like it's going to import the same script at the end of each loop.

Could you provide more information on what your exact problem is?

dongshan9619
dongshan9619 是的,脚本停止工作。 认为它必须做一些事情,内容加载点击,并且脚本不会出现
接近 6 年之前 回复
drfu80954
drfu80954 您是否尝试将<script>标记放在while循环上方?
接近 6 年之前 回复
douhuang3740
douhuang3740 脚本将在此部分加载<script type =“text / javascript”src =“<?php bloginfo('template_url');?> / js / youtube.js”> </ script> /js/youtube.js 有代码看这里pastebin.com/V3HpU0NY问题是它经常被定义,我不认为它应该。
接近 6 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐