【问题标题】:Works locally but not online在本地工作但不能在线
【发布时间】:2012-05-31 22:56:41
【问题描述】:

我有它,所以当您单击右上角的一个氢等元素时,它会在大中心 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>

【问题讨论】:

  • 控制台出现什么错误?
  • $('video').each 正在抛出 Uncaught Error: INVALID_STATE_ERR: DOM Exception 11

标签: javascript jquery css html


【解决方案1】:

错误在这里:

你正在尝试

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

【讨论】:

    【解决方案2】:

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

    您应该忽略控制台给您的错误,因为它将对您要查找的内容提供更多解释。

    这显然是抛出一个异常,无论你的异常是什么,都会显示错误消息,所以......你在定义文件的本地主机上尝试它。它们是在您的代码中用指针或要说的话来声明的吗?回头看看这里并在单击按钮时使用它?

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

    【讨论】:

    • 我使用 MAMP 以及使用 coda 的预览模式(我很确定使用 safari webmx)让它在本地工作。当我尝试在线打开它时它就不起作用了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-09
    • 1970-01-01
    • 1970-01-01
    • 2015-07-07
    • 1970-01-01
    • 2013-10-23
    相关资源
    最近更新 更多