简体   繁体   English

jQuery中的Sublime文本? 代码不起作用

[英]jQuery in Sublime text? Code not working

I am wondering if you can help. 我想知道您能否提供帮助。 I am previewing my code in a Firefox build system using Sublime text 3. The HTML and CSS are fine however my jQuery dosen't work despite being properly linked etc. Here is my code: 我正在使用Sublime文本3在Firefox构建系统中预览我的代码。HTML和CSS很好,但是尽管已正确链接,我的jQuery也无法正常工作。这是我的代码:

I just observed one thing, you are adding the class and removing it immediately on hover hence the div is unaffected 我只是观察到一件事,您正在添加类并在悬停时立即将其删除,因此div不受影响

Try this code, if you are trying to add the class only on hover and remove it when not hovered 如果尝试仅在悬停时添加类,而在未悬停时将其删除,请尝试以下代码

$('#manifesto').mouseover(function() {
    $(this).addClass('manifestotitle');
}).mouseout(function(){
    $(this).removeClass('manifestotitle');
});

For reference see the following jsfiddle: 作为参考,请参见以下jsfiddle:

http://jsfiddle.net/x3965auq/2/ http://jsfiddle.net/x3965auq/2/

Hope this helped 希望这对您有所帮助

I see in your CSS that "manifestotitle" refers to an id (#manifestotitle) could you try converting it to a class? 我在您的CSS中看到“ manifestotitle”是指一个id(#manifestotitle),您可以尝试将其转换为类吗?

EDIT: Ok, I think I got it. 编辑:好的,我想我明白了。 I downloaded your code and messed around a bit. 我下载了您的代码,并弄乱了一些。 This is what I changed to make it work: 这是我为了使其工作而进行的更改:

  1. Change your CDN for jquery to the official one: 将jquery的CDN更改为正式CDN:

  2. "manifestotitle" should be a class as your javascript is using it as one. “ manifestotitle”应为一类,因为您的javascript将该类作为一个类使用。 So you should make these changes. 因此,您应该进行这些更改。 In your HTML: 在您的HTML中:

    <div class="manifestotitle">

And in your CSS file: 在您的CSS文件中:

    `.manifestotitle {`
  1. Fix your selector in your js: 在您的js中修复选择器:

    $('#manifesto').hover(function () {

That got it working for me, hope it helps! 这对我有用,希望对您有所帮助!

Not an answer however need to show more code! 但是没有答案,需要显示更多代码!

It seems I can't get .hover() and .mouseover() functions to work at all with my code...here is a simple example (using a class rather than an ID also): 似乎我的代码根本无法使用.hover()和.mouseover()函数...这是一个简单的示例(也使用类而不是ID):

HTML:
    <div class="left"><a href="#"><b>Nick Reilly</b></a>
    <P><b><i>(Holding Page)</i></b></P></div>

CSS:
.left {
color: #000000;
left: 50px;
position: fixed;
top: 40px;
font-size: 18px;
z-index: 100;
line-height: 15px;
}

jQuery:
$(document).ready(function(){
 $("#left").mouseover(function(){
addClass('.red');
});
});

Surely this should simply change the text I have to red when the mouse is over it? 当然,这应该只是将鼠标悬停在我必须更改为红色的文本上吗? When I preview it in both a Firefox and Chrome build nothing happens! 当我同时在Firefox和Chrome浏览器中预览它时,什么也没发生!

Thanks 谢谢

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

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