适用于jsFiddle,但不适用于实时网站 [英] Works in jsFiddle but not on live site

查看:133
本文介绍了适用于jsFiddle,但不适用于实时网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

var add_time = function ($category) {
    'use strict';

    var time_element = $('<input size="7" class="time" placeholder="00:00" pattern="(?:(?:\\d:)?[0-5])?\\d:[0-5]\\d" title="Please insert a time in the form of [[h:]m]m:ss." />');

    if ($('.time').length === 0) {
        time_element.insertAfter($category.find('.add_time_button'));
    } else {
        time_element.insertAfter($('.time'));
    }
};

$('.add_time_button').click(function () {
    'use strict';

    add_time($(this).parentsWhen('.category'));
});

我不明白。没有控制台错误。一切看起来都很好。通过JSFiddle来实现它。没有。叹。问题全在标题中。这是jsFiddle: http://jsfiddle.net/gtr053/N2HmG/

I don't get it. No console errors. Everything looks fine to me. Ran it through JSFiddle. Nothing. Sigh. The question is all in the title. Here's the jsFiddle: http://jsfiddle.net/gtr053/N2HmG/

对于未来的读者来说,这将很快成为404。实时网站: http://bama.ua.edu/~tscrompton/annotation/

To future readers, this will be a 404 someday soon. Live site: http://bama.ua.edu/~tscrompton/annotation/

推荐答案

jsfiddle在 onLoad 中包围你的javascript。在您的网站上,您在哪里放置javascript?在头部?如果是这样,那就是它无法正常工作的原因。您必须在元素加载后分配您的onclicks和所有爵士乐。

jsfiddle surrounds your javascript in a onLoad. On your site, where are you putting the javascript? In the head section? If so, that's why it's not working. You have to assign your onclicks and all that jazz after the elements load.

编辑:

在你的javascript文件中你可以这样做:

In your javascript file you can do this:

$(document).ready(function(){
    //put the javascript from the jsfiddle in here
});

这篇关于适用于jsFiddle,但不适用于实时网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆