JSFiddle代码在网站中不起作用

时间:2017-04-16 20:22:00

标签: javascript css jsfiddle

我的一个简单的反网络欺凌插件的代码在JSFiddle中完美运行,但在我的网站中不起作用,即使我添加document.ready并使用像jslint这样的c + p清理程序。我研究了几个SO问题,但没有一个答案适合我。

这是JSFiddle: The Code

以下是我在网站上使用的确切JS:

$(document).ready(function() {
  var triggerWords = ["stupid",
    "ugly",
    "fat",
    "kill",
    "dumb",
    "idiot",
    "moron",
    "no future",
    "nerd",
    "smelly",
    "stinks",
    "stink",
    "fatso",
    "freak",
    "weirdo",
    "crazy",
    "ass",
    "asshole",
    "bitch",
    "abortion",
    "disgusting",
    "loser",
    "lame",
    "failure",
    "unlovable",
    "shit",
    "fuck",
    "worthless",
    "douchebag",
    "douche",
    "I hate you",
    "retard",
    "retarded",
    "pervert",
    "overdramatic",
    "prick",
    "hater",
    "hate",
    "disgrace",
    "obese",
    "lazy",
    "unloved",
    "geek",
    "unwanted",
    "emo",
    "annoying",
    "untalented",
    "whore",
    "obnoxious",
    "slut",
    "homo",
    "useless",
    "psycho",
    "pathetic",
    "selfish",
    "monster",
    "coward",
    "naive",
    "gullible",
    "crybaby",
    "unqualified",
    "hopeless",
    "sleazy",

  ];
  $(document).on('keyup', 'textarea', function humhm {
    for (var i = 0; i < triggerWords.length; i++) {
      if ($(this).val().toLowerCase().indexOf(triggerWords[i]) != -1) {

        document.getElementById("styled").className = "mystyle";
        document.getElementById("shover").className = "mason";
        const messages = ['<img src="https://lh3.googleusercontent.com/TzOBj6xt9unc8n41fMyUZ46FG4MRXBK6wkdOtzmKJPoLa9gBYNwZYQkRB8fsboqM1LHh3ahxOLOlyKsH1zG1qmGHgbS6IK-yZtv6Duo6_thwIKEVRY7BZNr2JJzAkYviyKp_q7SPWnp1"width="200px" class="floater" onclick="javascript:eraseText();">Words mean a lot. Their echoes can brighten someone\'s day. Or they can make a bad day worse. Consider the person behind the screen.', '<img src="https://lh3.googleusercontent.com/TzOBj6xt9unc8n41fMyUZ46FG4MRXBK6wkdOtzmKJPoLa9gBYNwZYQkRB8fsboqM1LHh3ahxOLOlyKsH1zG1qmGHgbS6IK-yZtv6Duo6_thwIKEVRY7BZNr2JJzAkYviyKp_q7SPWnp1"width="200px" class="floater" onclick="javascript:eraseText();">Your words can be a force for happiness or dejection. Choose carefully.', 'Be mindful of your words. Would you say this in real life?', 'Consider the impact your words may have. A couple insults slung casually can be much more significant to others.', 'Words that are insignificant to you can deeply hurt another. Be empathetic. Be nice.'];
        const randomIndex = Math.round(Math.random(messages.length * 10 - 0.5));
        document.getElementById("shover").innerHTML = messages[randomIndex];

        document.getElementById("usual").className = "noshow";
        document.getElementById("trigger").className = "norm";

      }
    }
  });


});
'

没有控制台错误。

2 个答案:

答案 0 :(得分:1)

你导入的是JQuery吗?通常罕见的#39;来自简单问题的错误。

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

我建议您使用JQuery使代码更具人性化,您可以替换document.getElementById("ID_VALUE")的所有$('#ID_VALUE')

PD:祝好反网络哄骗。重要的事情。

答案 1 :(得分:1)

您需要导入jQuery。

JSFiddle确实导入了它。 enter image description here