在本地工作,但不能在线工作

Works locally but not online

本文关键字:工作 但不能 在线      更新时间:2023-09-26

我有它,所以当你点击右上角的元素时,它会在大中心div中播放一个视频并显示有关氢的信息。我让它在本地工作,但我无法让它在线工作。请任何帮助会很棒。

这是我项目的链接http://travismichael.net/periodic_elements/

这是我网站的脚本

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

$('div.video').hide();
$('.icon').click(function(){
    var id=$(this).data('id'),
        thisDiv=$("div.video[data-id='" + id +"']"),
        thisVideo=$("div.video[data-id='" + id +"']").find('video');
    $('video').each(function() {
        this.pause();
        this.currentTime = 0;
    });
       $('div.video').not(thisDiv).fadeOut('fast');
       thisDiv.fadeIn();      
       thisVideo.get(0).play();   
    });
});
</script>
<script type="text/javascript">
$("#periodictable td").hover(function() {
      $(this).stop().animate({opacity: "1"}, 'fast');
    },
    function() {
      $(this).stop().animate({opacity: ".7"}, 'slow');
    });
</script>

错误在这里:

您正在尝试使用

var thisDiv = ("div.video[data-id='" + id +"']");// but it returns jQuery object, 
                                                 // not element
// Thats why below statement will not work
// because it works on element
alert(thisDiv.nodeType);

所以你应该这样尝试:

var thisDiv = ("div.video[data-id='" + id +"']")[0]; // returns the element
alert(thisDiv.nodeType); // and then get the nodeType

选中后,我收到一条错误消息,指出元素未定义。

您应该跳过控制台给您的错误,因为它将为您正在寻找的内容提供更多解释。

它显然抛出了一个异常,无论您的异常是什么,都会显示错误消息,所以......您可以在定义文件的本地主机上尝试。它们是否在您的代码中声明了指针或要说的东西,请返回此处并在单击按钮时使用它?

看起来您的函数应该包含这些声明,或者您可以使它们全局化,如果没有更多信息,您不确定......

相关文章: