简体   繁体   English

错误:html5 Javascript中未定义$

[英]Error:$ is not defined in html5 Javascript

i am working in DOM i want to run marquee on header through given below library. 我在DOM中工作,我想通过下面的库在标题上运行选取框。 this is my error below. 这是我下面的错误。 Please help me out. 请帮帮我。 theres an error of $ which is not defined according code but I have already defined. $的错误没有根据代码定义,但是我已经定义了。 The marquee is actually not working on Mac Safari browser. 该选框实际上不适用于Mac Safari浏览器。

Error:$ is not defined

Code: 码:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="https://rawgithub.com/aamirafridi/jQuery.Marquee/master/jquery.marquee.min.js"></script>
<div onclick="myfunction()" class="marquee" style="width: 300px; overflow: hidden;">
<script>
function myfunction(){
  $('#marquee').marquee();
}
</script>

the library is already included of jquery. 该库已经包含在jquery中。

You are calling the <div class='marquee'> element by using a id selector $("#marquee") . 您正在通过使用id选择器$("#marquee")调用<div class='marquee'>元素。

Try using $(".marquee") instead. 尝试改用$(".marquee")

More info about jQuery selectors 有关jQuery选择器的更多信息

This worked for me with some corrections as said above. 如上所述,这对我起作用并进行了一些更正。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="https://rawgithub.com/aamirafridi/jQuery.Marquee/master/jquery.marquee.min.js"></script>
<div onclick="myfunction()" class="marquee" style="width: 300px; overflow: hidden;"> hello </div>
<script>
  function myfunction() {
    alert("marquee");
    $('.marquee').marquee();
  }

</script>

Check fiddle 检查小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM