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

时间:2022-11-22 20:18:00

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虽然正确链接等,但仍然无法工作。这是我的代码:

3 个解决方案

#1


0  

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

希望这有帮助

#2


0  

I see in your CSS that "manifestotitle" refers to an id (#manifestotitle) could you try converting it to a class?

我在你的CSS中看到“manifestotitle”指的是一个id(#manststotitle)你可以尝试将它转换为一个类吗?

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:

    将您的CDN for jquery更改为官方CDN:

  2. "manifestotitle" should be a class as your javascript is using it as one. So you should make these changes. In your HTML:

    “manifestotitle”应该是一个类,因为你的javascript正在使用它。所以你应该做出这些改变。在您的HTML中:

    <div class="manifestotitle">

And in your CSS file:

在你的CSS文件中:

    `.manifestotitle {`
  1. Fix your selector in your js:

    修复你的选择器在你的js:

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

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

That got it working for me, hope it helps!

这让它对我有用,希望它有所帮助!

#3


-1  

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

谢谢

#1


0  

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

希望这有帮助

#2


0  

I see in your CSS that "manifestotitle" refers to an id (#manifestotitle) could you try converting it to a class?

我在你的CSS中看到“manifestotitle”指的是一个id(#manststotitle)你可以尝试将它转换为一个类吗?

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:

    将您的CDN for jquery更改为官方CDN:

  2. "manifestotitle" should be a class as your javascript is using it as one. So you should make these changes. In your HTML:

    “manifestotitle”应该是一个类,因为你的javascript正在使用它。所以你应该做出这些改变。在您的HTML中:

    <div class="manifestotitle">

And in your CSS file:

在你的CSS文件中:

    `.manifestotitle {`
  1. Fix your selector in your js:

    修复你的选择器在你的js:

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

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

That got it working for me, hope it helps!

这让它对我有用,希望它有所帮助!

#3


-1  

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

谢谢