简体   繁体   English

jQuery不再起作用了(在我的网站上)

[英]jQuery just does not work anymore (on my site)

So, I've got a tiny simple jquery going on here where a div will slide down just a bit. 因此,我在这里进行了一个小小的简单jquery,其中div会向下滑动一点。 But NOTHING in the jquery file works: 但是jquery文件中的什么都没用:

$('.starterLink').click(function(){
    $('.starterSummary').animate({'width': '230px'});
      });    
});

However, I have a different website with the exact same code, and that one works! 但是,我有一个完全相同的代码的不同网站,并且这个网站有效! Bu I need it to work on this one. Bu我需要它来完成这一工作。 Any suggestions? 有什么建议么? Can you see anything wrong here? 您在这里看到任何错误吗?

html: 的HTML:

<div class="packages">
    <div class="starter">
        <span><a href="@Href("#")" class="starterLink"><h1 class="starterLink">Starter Pack</h1></a></span>
    </div>
    <div class="business">
        <span><h1>Business</h1></span>
    </div>
    <div class="corporate">
        <span><h1>Corporate</h1></span>
    </div>
</div>
<div class="packageSummaries">
    <div class="starterSummary">
        <h1>Free Advertising</h1>
        <p></p>
        <a href="" class="roundedButton silver">Service Link</a>
    </div>
    <div class="businessSummary">
        <h1></h1>
        <p>Service summary</p>
        <a href="" class="roundedButton silver">Service Link</a>
    </div>
    <div class="corporateSummary">
        <h1>Service Heading</h1>
        <p>Service summary</p>
        <a href="" class="roundedButton silver">Service Link</a>
    </div>
</div>

css: CSS:

.packages {
    width: 60%;
    background-image: url('../Images/pres-bg.png');
    background-repeat: repeat;
    float: left;
}
.packageSummaries {
    width: 40%;
    float: right;
}
.starter {
    position: relative;
    width: 35%;
    float: left;
    height: 140px;
    overflow: hidden;

    background-color: #02A7FF;
    opacity: .7;
}
.starter span {
  position: absolute;    
  bottom: 0;    
  right: 0; 
}
.business {
    position: relative;
    width: 35%;
    float: left;
    height: 140px;
    overflow: hidden;

    background-color: #FF7402;
    opacity: .7;
}
.business span {
  position: absolute;    
  bottom: 0;    
  right: 0; 
}

.corporate {
    position: relative;
    width: 30%;
    float: left;
    height: 140px;
    overflow: hidden;
    background-color: #111111;
    opacity: .7;
}
.corporate span {
  position: absolute;    
  bottom: 0;    
  right: 0; 
}
.starterSummary {
    padding-left: 8px;
    margin: 0;
    width: 0px;
    background-color: Blue;
    overflow: hidden;
}
.businessSummary {
    padding-left: 8px;
    margin: 0;
    width: 0px;
    overflow: hidden;

}
.corporateSummary {
    padding-left: 8px;
    margin: 0;
    width: 0px;
    overflow: hidden;

}

Any help at all is greatly appreciated. 任何帮助都将不胜感激。 This has got me stumped. 这让我难过。

Thank you 谢谢

Seems like you have a }); 好像您有一个}); to much in your jQuery. 在您的jQuery中有很多。 You should consider checking the errorconsole in the browser you're using. 您应该考虑在使用的浏览器中检查错误控制台。 It would probably display that error. 它可能会显示该错误。

$('.starterLink').click(function(){
    $('.starterSummary').animate({'width': '230px'});
      });    
});

UPDATE 更新

It could also be because you're missing the reference to jquery.js. 也可能是因为您缺少对jquery.js的引用。 Check that it's included as a script-tag and that the URL is correct. 检查它是否包含为脚本标签,以及URL是否正确。

If jQuery is not present you should get an error. 如果不存在jQuery,您将收到错误消息。 Try to type $ on the browser console and see if you get back the jQuery object. 尝试在浏览器控制台上键入$,然后查看是否返回jQuery对象。

Try to load jquery from Google or other CDN. 尝试从Google或其他CDN加载jquery。

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js" type="text/javascript"></script>

There is a syntax error in your script: 您的脚本中存在语法错误:

$('.starterLink').click(function(){
    $('.starterSummary').animate({'width': '230px'});
    // -->  });    
});
<a href="@Href("#")"..>

The quotes are wrong. 引号是错误的。

Try w3 validator and jslint to see if everything is valid. 尝试使用w3验证程序和jslint来查看所有内容是否有效。
Also a link to the actual site would help if it's possible. 如果可能的话,指向实际站点的链接也将有所帮助。

Looks like a simple syntax error with a }); 看起来像一个带有});的简单语法错误}); that shouldn't be there. 那不应该在那里。

$('.starterLink').click(function(){
    $('.starterSummary').animate({'width': '230px'});    
});

If you have an error in your code then none of the Javascript will work. 如果您的代码中有错误,则所有Javascript均不起作用。

You can usually track down the issue using Firebug (if you're using Firefox), or just your browser's developer console. 通常,您可以使用Firebug (如果使用的是Firefox)或浏览器的开发人员控制台来查找问题。

不匹配的花括号})href="@Href("#")"是什么意思?

replace href="@Href("#")" with href="@Href('"'#'"')" href="@Href('"'#'"')"替换href="@Href("#")" href="@Href('"'#'"')"

here is a DEMO 这是一个演示

you may not be able to see the animation because it'll try to navigate to the link, here you can see the animation http://jsfiddle.net/wvaE3/3/ 您可能无法看到动画,因为它会尝试导航到链接,在这里您可以看到动画http://jsfiddle.net/wvaE3/3/

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

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